Пример #1
0
        public static void DeserializeField(DeserializeContext context, BinaryReader br, ref string value)
        {
            if (!context.Walk(ref value))
            {
                return;
            }

            value = br.ReadString();             // TODO: one day we might like to not allocate here.
            context.VisitObject(value);
        }
Пример #2
0
        public static void DeserializeArrayField <T>(DeserializeContext context, BinaryReader br, ref T[] array)
        {
            if (!context.Walk(ref array))
            {
                return;
            }

            array = new T[br.ReadSmallInt32()];
            context.VisitObject(array);
            for (var i = 0; i < array.Length; i++)
            {
                Field.Deserialize(context, br, ref array[i]);
            }
        }
Пример #3
0
        public static void Deserialize <T>(DeserializeContext context, BinaryReader br, LinkedList <T> list)
        {
            context.VisitObject(list);

            var count = br.ReadSmallInt32();

            list.Clear();

            for (var i = 0; i < count; i++)
            {
                var item = default(T);
                Field.Deserialize(context, br, ref item);
                list.AddLast(item);
            }
        }
Пример #4
0
        public static void Deserialize <T>(DeserializeContext context, BinaryReader br, Queue <T> queue)
        {
            context.VisitObject(queue);

            var count = br.ReadSmallInt32();

            queue.Clear();

            for (var i = 0; i < count; i++)
            {
                var item = default(T);
                Field.Deserialize(context, br, ref item);
                queue.Enqueue(item);
            }
        }
Пример #5
0
        public static void Deserialize <T>(DeserializeContext context, BinaryReader br, Stack <T> stack)
        {
            context.VisitObject(stack);

            var count = br.ReadSmallInt32();

            stack.Clear();

            for (var i = 0; i < count; i++)
            {
                var item = default(T);
                Field.Deserialize(context, br, ref item);
                stack.Push(item);
            }
        }
Пример #6
0
        public static void Deserialize <TKey, TValue>(DeserializeContext context, BinaryReader br, OrderedDictionary <TKey, TValue> dictionary)
        {
            context.VisitObject(dictionary);

            int count = br.ReadSmallInt32();

            dictionary.Clear();

            for (int i = 0; i < count; i++)
            {
                TKey   key   = default(TKey);
                TValue value = default(TValue);
                Field.Deserialize(context, br, ref key);
                Field.Deserialize(context, br, ref value);
                dictionary.Add(key, value);
            }
        }
Пример #7
0
        public static void DeserializeField(DeserializeContext context, BinaryReader br,
                                            ref StringBuilder stringBuilder)
        {
            if (!context.Walk(ref stringBuilder))
            {
                return;
            }

            var length = br.ReadSmallInt32();

            stringBuilder        = new StringBuilder(length);
            stringBuilder.Length = length;
            context.VisitObject(stringBuilder);
            for (var i = 0; i < length; i++)
            {
                stringBuilder[i] = br.ReadChar();
            }
        }
Пример #8
0
        public static void DeserializeArray2DField <T>(DeserializeContext context, BinaryReader br, ref T[,] array)
        {
            if (!context.Walk(ref array))
            {
                return;
            }

            int length0, length1;

            array = new T[length0 = br.ReadSmallInt32(), length1 = br.ReadSmallInt32()];

            context.VisitObject(array);

            for (var i = 0; i < length0; i++)
            {
                for (var j = 0; j < length1; j++)         // NOTE: Arrays are contiguious on their rightmost (last) dimension
                {
                    Field.Deserialize(context, br, ref array[i, j]);
                }
            }
        }
Пример #9
0
        public static void DeserializeArray3DField <T>(DeserializeContext context, BinaryReader br, ref T[,,] array)
        {
            if (!context.Walk(ref array))
            {
                return;
            }

            int length0, length1, length2;

            array = new T[length0 = br.ReadSmallInt32(), length1 = br.ReadSmallInt32(), length2 = br.ReadSmallInt32()];

            context.VisitObject(array);

            for (var i = 0; i < length0; i++)
            {
                for (var j = 0; j < length1; j++)
                {
                    for (var k = 0; k < length2; k++)
                    {
                        Field.Deserialize(context, br, ref array[i, j, k]);
                    }
                }
            }
        }