コード例 #1
0
ファイル: ContentFormat.cs プロジェクト: alex521/ycs
        internal static ContentFormat Read(IUpdateDecoder decoder)
        {
            var key   = decoder.ReadKey();
            var value = decoder.ReadJson();

            return(new ContentFormat(key, value));
        }
コード例 #2
0
ファイル: EncodingUtils.cs プロジェクト: alex521/ycs
        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);
        }
コード例 #3
0
ファイル: EncodingUtils.cs プロジェクト: alex521/ycs
        /// <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);
        }
コード例 #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)));
        }
コード例 #5
0
ファイル: ContentAny.cs プロジェクト: alex521/ycs
        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));
        }
コード例 #6
0
ファイル: YDoc.cs プロジェクト: 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);
        }
コード例 #7
0
ファイル: ContentJson.cs プロジェクト: alex521/ycs
        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));
        }
コード例 #8
0
ファイル: ContentType.cs プロジェクト: alex521/ycs
        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");
            }
        }
コード例 #9
0
ファイル: EncodingUtils.cs プロジェクト: alex521/ycs
        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}");
            }
        }
コード例 #10
0
ファイル: ContentDeleted.cs プロジェクト: alex521/ycs
        internal static ContentDeleted Read(IUpdateDecoder decoder)
        {
            var length = decoder.ReadLength();

            return(new ContentDeleted(length));
        }
コード例 #11
0
 internal static YMap Read(IUpdateDecoder decoder)
 {
     return(new YMap());
 }
コード例 #12
0
 internal static ContentString Read(IUpdateDecoder decoder)
 {
     return(new ContentString(decoder.ReadString()));
 }
コード例 #13
0
 internal static YArray Read(IUpdateDecoder decoder)
 {
     return(new YArray());
 }
コード例 #14
0
ファイル: ContentEmbed.cs プロジェクト: alex521/ycs
        internal static ContentEmbed Read(IUpdateDecoder decoder)
        {
            var content = decoder.ReadJson();

            return(new ContentEmbed(content));
        }
コード例 #15
0
ファイル: ContentBinary.cs プロジェクト: alex521/ycs
        internal static ContentBinary Read(IUpdateDecoder decoder)
        {
            var content = decoder.ReadBuffer();

            return(new ContentBinary(content));
        }