Exemplo n.º 1
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.º 2
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.º 3
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.º 4
0
 internal static ContentString Read(IUpdateDecoder decoder)
 {
     return(new ContentString(decoder.ReadString()));
 }