public override FSharpMap <TKey, TValue> Deserialize(ref byte[] bytes, int offset, DirtyTracker tracker, out int byteSize)
        {
            // tracker.Dirty(); // immutable

            var length = BinaryUtil.ReadInt32(ref bytes, offset);

            if (length == -1)
            {
                byteSize = 4;
                return(null);
            }
            ZeroFormatterSerializer.ValidateNewLength(length);

            var startOffset = offset;

            offset += 4;
            int size;
            var result = new Tuple <TKey, TValue> [length];

            for (int i = 0; i < length; i++)
            {
                var kvp = kvpFormatter.Deserialize(ref bytes, offset, tracker, out size);
                result[i] = Tuple.Create(kvp.Key, kvp.Value);
                offset   += size;
            }

            byteSize = offset - startOffset;
            return(MapModule.OfArray(result));
        }
        public override FSharpList <T> Deserialize(ref byte[] bytes, int offset, DirtyTracker tracker, out int byteSize)
        {
            // tracker.Dirty(); FSharpList is immutable

            var length = BinaryUtil.ReadInt32(ref bytes, offset);

            if (length == -1)
            {
                byteSize = 4;
                return(null);
            }

            var startOffset = offset;

            offset += 4;
            int size;

            ZeroFormatterSerializer.ValidateNewLength(length);
            var result = new T[length];

            for (int i = 0; i < length; i++)
            {
                result[i] = formatter.Deserialize(ref bytes, offset, tracker, out size);
                offset   += size;
            }

            byteSize = offset - startOffset;
            return(ListModule.OfArray(result));
        }
Exemplo n.º 3
0
        public override ISet <T> Deserialize(ref byte[] bytes, int offset, DirtyTracker tracker, out int byteSize)
        {
            tracker.Dirty(); // can not track so mark as dirty.

            var length = BinaryUtil.ReadInt32(ref bytes, offset);

            if (length == -1)
            {
                byteSize = 4;
                return(null);
            }
            ZeroFormatterSerializer.ValidateNewLength(length);

            var startOffset = offset;

            offset += 4;
            int size;
            var comparer = ZeroFormatterEqualityComparer <T> .NondeterministicSafeFallbacked;
            var result   = new HashSet <T>(comparer);

            for (int i = 0; i < length; i++)
            {
                result.Add(formatter.Deserialize(ref bytes, offset, tracker, out size));
                offset += size;
            }

            byteSize = offset - startOffset;
            return(result);
        }
Exemplo n.º 4
0
        public override IReadOnlyDictionary <TKey, TValue> Deserialize(ref byte[] bytes, int offset, DirtyTracker tracker, out int byteSize)
        {
            // tracker.Dirty(); // immutable

            var length = BinaryUtil.ReadInt32(ref bytes, offset);

            if (length == -1)
            {
                byteSize = 4;
                return(null);
            }
            ZeroFormatterSerializer.ValidateNewLength(length);

            var startOffset = offset;

            offset += 4;
            int size;
            var comparer = ZeroFormatterEqualityComparer <TKey> .NondeterministicSafeFallbacked;
            var result   = new Dictionary <TKey, TValue>(length, comparer);

            for (int i = 0; i < length; i++)
            {
                var kvp = formatter.Deserialize(ref bytes, offset, tracker, out size);
                result.Add(kvp.Key, kvp.Value);
                offset += size;
            }

            byteSize = offset - startOffset;
            return(result);
        }
Exemplo n.º 5
0
        public override T[] Deserialize(ref byte[] bytes, int offset, DirtyTracker tracker, out int byteSize)
        {
            tracker.Dirty(); // can not track so mark as dirty.

            var length = BinaryUtil.ReadInt32(ref bytes, offset);

            if (length == -1)
            {
                byteSize = 4;
                return(null);
            }

            var startOffset = offset;

            offset += 4;
            int size;

            ZeroFormatterSerializer.ValidateNewLength(length);
            var result = new T[length];

            for (int i = 0; i < length; i++)
            {
                result[i] = formatter.Deserialize(ref bytes, offset, tracker, out size);
                offset   += size;
            }

            byteSize = offset - startOffset;
            return(result);
        }
Exemplo n.º 6
0
        public override ILookup <TKey, TElement> Deserialize(ref byte[] bytes, int offset, DirtyTracker tracker, out int byteSize)
        {
            // tracker.Dirty(); // ilookup is immutable

            var length = BinaryUtil.ReadInt32(ref bytes, offset);

            if (length == -1)
            {
                byteSize = 4;
                return(null);
            }
            ZeroFormatterSerializer.ValidateNewLength(length);

            var startOffset = offset;

            offset += 4;
            var lastOffset = offset;
            var lookup     = DeserializeSequence(bytes, offset, tracker, length).ToLookup(x => x.Item1, x =>
            {
                lastOffset = x.Item3; // capture in lambda is overhead but lookup can only create from ToLookup
                return(x.Item2);
            });

            byteSize = lastOffset - startOffset;
            return(lookup);
        }
Exemplo n.º 7
0
        public override Int32[] Deserialize(ref byte[] bytes, int offset, DirtyTracker tracker, out int byteSize)
        {
            tracker.Dirty(); // can not track so mark as dirty.

            var length = BinaryUtil.ReadInt32(ref bytes, offset);

            if (length == -1)
            {
                byteSize = 4;
                return(null);
            }
            else
            {
                byteSize = length * 4 + 4;
            }

            var arraySize = length * 4;

            ZeroFormatterSerializer.ValidateNewLength(arraySize);
            var result = new Int32[length];

            Buffer.BlockCopy(bytes, offset + 4, result, 0, arraySize);

            return(result);
        }
Exemplo n.º 8
0
        public override TCollection Deserialize(ref byte[] bytes, int offset, DirtyTracker tracker, out int byteSize)
        {
            tracker.Dirty(); // can not track so mark as dirty.

            var length = BinaryUtil.ReadInt32(ref bytes, offset);

            if (length == -1)
            {
                byteSize = 4;
                return(default(TCollection));
            }

            var startOffset = offset;

            offset += 4;
            int size;

            ZeroFormatterSerializer.ValidateNewLength(length);
            TCollection result;

            if (isList)
            {
                // optmize fixed length.
                result = (TCollection)(object)new List <TElement>(length);
            }
            else
            {
                result = new TCollection();
            }
            for (int i = 0; i < length; i++)
            {
                result.Add(formatter.Deserialize(ref bytes, offset, tracker, out size));
                offset += size;
            }

            byteSize = offset - startOffset;
            return(result);
        }
Exemplo n.º 9
0
        public override ILookup <TKey, TElement> Deserialize(ref byte[] bytes, int offset, DirtyTracker tracker, out int byteSize)
        {
            // tracker.Dirty(); // ilookup is immutable

            var length = BinaryUtil.ReadInt32(ref bytes, offset);

            if (length == -1)
            {
                byteSize = 4;
                return(null);
            }
            ZeroFormatterSerializer.ValidateNewLength(length);

            var startOffset = offset;

            offset += 4;
            var lastOffset = offset;
            var comparer   = ZeroFormatterEqualityComparer <TKey> .NondeterministicSafeFallbacked;
            var sequence   = new DeserializeSequence(bytes, offset, tracker, length, keyFormatter, valueFormatter);
            var lookup     = sequence.ToLookup(x => x.Item1, x => x.Item2, comparer);

            byteSize = sequence.offset - startOffset;
            return(lookup);
        }