Exemplo n.º 1
0
        internal static ContentFormat Read(IUpdateDecoder decoder)
        {
            var key   = decoder.ReadKey();
            var value = decoder.ReadJson();

            return(new ContentFormat(key, value));
        }
Exemplo n.º 2
0
        public static IDictionary <int, List <AbstractStruct> > ReadClientStructRefs(IUpdateDecoder decoder, YDoc doc)
        {
            var clientRefs = new Dictionary <int, List <AbstractStruct> >();

            var numOfStateUpdates = decoder.Reader.ReadVarUint();

            for (int i = 0; i < numOfStateUpdates; i++)
            {
                var numberOfStructs = (int)decoder.Reader.ReadVarUint();
                Debug.Assert(numberOfStructs >= 0);

                var refs   = new List <AbstractStruct>(numberOfStructs);
                var client = decoder.ReadClient();
                var clock  = (int)decoder.Reader.ReadVarUint();

                clientRefs[client] = refs;

                for (int j = 0; j < numberOfStructs; j++)
                {
                    var info = decoder.ReadInfo();
                    if ((Bits.Bits5 & info) != 0)
                    {
                        // The item that was originally to the left of this item.
                        var leftOrigin = (info & Bit.Bit8) == Bit.Bit8 ? (ID?)decoder.ReadLeftId() : null;
                        // The item that was originally to the right of this item.
                        var rightOrigin        = (info & Bit.Bit7) == Bit.Bit7 ? (ID?)decoder.ReadRightId() : null;
                        var cantCopyParentInfo = (info & (Bit.Bit7 | Bit.Bit8)) == 0;
                        var hasParentYKey      = cantCopyParentInfo ? decoder.ReadParentInfo() : false;

                        // If parent == null and neither left nor right are defined, then we know that 'parent' is child of 'y'
                        // and we read the next string as parentYKey.
                        // It indicates how we store/retrieve parent from 'y.share'.
                        var parentYKey = cantCopyParentInfo && hasParentYKey?decoder.ReadString() : null;

                        var str = new Item(
                            new ID(client, clock),
                            null,                                                                                                                                   // left
                            leftOrigin,
                            null,                                                                                                                                   // right
                            rightOrigin,                                                                                                                            // rightOrigin
                            cantCopyParentInfo && !hasParentYKey ? decoder.ReadLeftId() : (parentYKey != null ? (object)doc.Get <AbstractType>(parentYKey) : null), // parent
                            cantCopyParentInfo && (info & Bit.Bit6) == Bit.Bit6 ? decoder.ReadString() : null,                                                      // parentSub
                            ReadItemContent(decoder, info)                                                                                                          // content
                            );

                        refs.Add(str);
                        clock += str.Length;
                    }
                    else
                    {
                        var length = decoder.ReadLength();
                        refs.Add(new GC(new ID(client, clock), length));
                        clock += length;
                    }
                }
            }

            return(clientRefs);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Read the next Item in a Decoder and fill this Item with the read data.
        /// <br/>
        /// This is called when data is received from a remote peer.
        /// </summary>
        public static void ReadStructs(IUpdateDecoder decoder, Transaction transaction, StructStore store)
        {
            var clientStructRefs = ReadClientStructRefs(decoder, transaction.Doc);

            store.MergeReadStructsIntoPendingReads(clientStructRefs);
            store.ResumeStructIntegration(transaction);
            store.CleanupPendingStructs();
            store.TryResumePendingDeleteReaders(transaction);
        }
Exemplo n.º 4
0
        internal static ContentDoc Read(IUpdateDecoder decoder)
        {
            var guidStr = decoder.ReadString();

            var opts = YDocOptions.Read(decoder);

            opts.Guid = guidStr;

            return(new ContentDoc(new YDoc(opts)));
        }
Exemplo n.º 5
0
        internal static ContentAny Read(IUpdateDecoder decoder)
        {
            var length = decoder.ReadLength();
            var cs     = new List <object>(length);

            for (int i = 0; i < length; i++)
            {
                var c = decoder.ReadAny();
                cs.Add(c);
            }

            return(new ContentAny(cs));
        }
Exemplo n.º 6
0
Arquivo: YDoc.cs Projeto: alex521/ycs
        internal static YDocOptions Read(IUpdateDecoder decoder)
        {
            var dict = (IDictionary <string, object>)decoder.ReadAny();

            var result = new YDocOptions();

            result.Gc       = dict.ContainsKey("gc") ? (bool)dict["gc"] : true;
            result.Guid     = dict.ContainsKey("guid") ? dict["guid"].ToString() : System.Guid.NewGuid().ToString("D");
            result.Meta     = dict.ContainsKey("meta") ? dict["meta"] as Dictionary <string, string> : null;
            result.AutoLoad = dict.ContainsKey("autoLoad") ? (bool)dict["autoLoad"] : false;

            return(result);
        }
Exemplo n.º 7
0
        internal static ContentJson Read(IUpdateDecoder decoder)
        {
            var len     = decoder.ReadLength();
            var content = new List <object>(len);

            for (int i = 0; i < len; i++)
            {
                var    jsonStr = decoder.ReadString();
                object jsonObj = string.Equals(jsonStr, "undefined")
                    ? null
                    : Newtonsoft.Json.JsonConvert.DeserializeObject(jsonStr);
                content.Add(jsonObj);
            }

            return(new ContentJson(content));
        }
Exemplo n.º 8
0
        internal static ContentType Read(IUpdateDecoder decoder)
        {
            var typeRef = decoder.ReadTypeRef();

            switch (typeRef)
            {
            case YArray.YArrayRefId:
                var arr = YArray.Read(decoder);
                return(new ContentType(arr));

            case YMap.YMapRefId:
                var map = YMap.Read(decoder);
                return(new ContentType(map));

            case YText.YTextRefId:
                var text = YText.Read(decoder);
                return(new ContentType(text));

            default:
                throw new NotImplementedException($"Type {typeRef} not implemented");
            }
        }
Exemplo n.º 9
0
        public static IContent ReadItemContent(IUpdateDecoder decoder, byte info)
        {
            switch (info & Bits.Bits5)
            {
            case 0:     // GC
                throw new Exception("GC is not ItemContent");

            case 1:     // Deleted
                return(ContentDeleted.Read(decoder));

            case 2:     // JSON
                return(ContentJson.Read(decoder));

            case 3:     // Binary
                return(ContentBinary.Read(decoder));

            case 4:     // String
                return(ContentString.Read(decoder));

            case 5:     // Embed
                return(ContentEmbed.Read(decoder));

            case 6:     // Format
                return(ContentFormat.Read(decoder));

            case 7:     // Type
                return(ContentType.Read(decoder));

            case 8:     // Any
                return(ContentAny.Read(decoder));

            case 9:     // Doc
                return(ContentDoc.Read(decoder));

            default:
                throw new InvalidOperationException($"Content type not recognized: {info}");
            }
        }
Exemplo n.º 10
0
        internal static ContentDeleted Read(IUpdateDecoder decoder)
        {
            var length = decoder.ReadLength();

            return(new ContentDeleted(length));
        }
Exemplo n.º 11
0
 internal static YMap Read(IUpdateDecoder decoder)
 {
     return(new YMap());
 }
Exemplo n.º 12
0
 internal static ContentString Read(IUpdateDecoder decoder)
 {
     return(new ContentString(decoder.ReadString()));
 }
Exemplo n.º 13
0
 internal static YArray Read(IUpdateDecoder decoder)
 {
     return(new YArray());
 }
Exemplo n.º 14
0
        internal static ContentEmbed Read(IUpdateDecoder decoder)
        {
            var content = decoder.ReadJson();

            return(new ContentEmbed(content));
        }
Exemplo n.º 15
0
        internal static ContentBinary Read(IUpdateDecoder decoder)
        {
            var content = decoder.ReadBuffer();

            return(new ContentBinary(content));
        }