Пример #1
0
        public override object ReadValue(Stream stream, DeserializerSession session)
        {
            var buffer = session.GetBuffer(16);

            stream.Read(buffer, 0, 16);
            return(new Guid(buffer)); //TODO: cap array?
        }
Пример #2
0
 public static uint ReadUInt16(this Stream self, DeserializerSession session)
 {
     var buffer = session.GetBuffer(2);
     self.Read(buffer, 0, 2);
     var res = BitConverter.ToUInt16(buffer, 0);
     return res;
 }
        public override object ReadValue(Stream stream, DeserializerSession session)
        {
            var elementSerializer = session.Serializer.GetDeserializerByManifest(stream, session);
            //read the element type
            var elementType = elementSerializer.GetElementType();
            //get the element type serializer
            var length = stream.ReadInt32(session);
            var array  = Array.CreateInstance(elementType, length); //create the array

            if (session.Serializer.Options.PreserveObjectReferences)
            {
                session.TrackDeserializedObject(array);
            }

            if (elementType.IsFixedSizeType())
            {
                var size      = elementType.GetTypeSize();
                var totalSize = size * length;
                var buffer    = session.GetBuffer(totalSize);
                stream.Read(buffer, 0, totalSize);
                Buffer.BlockCopy(buffer, 0, array, 0, totalSize);
            }
            else
            {
                for (var i = 0; i < length; i++)
                {
                    var value = elementSerializer.ReadValue(stream, session); //read the element value
                    array.SetValue(value, i);                                 //set the element value
                }
            }

            return(array);
        }
Пример #4
0
 public static int ReadInt32(this Stream self, DeserializerSession session)
 {
     var buffer = session.GetBuffer(4);
     self.Read(buffer, 0, 4);
     var res = BitConverter.ToInt32(buffer, 0);
     return res;
 }
Пример #5
0
        public static string ReadString(this Stream stream, DeserializerSession session)
        {
            var length = stream.ReadByte();

            switch (length)
            {
            case 0:
                return(null);

            case 255:
                length = stream.ReadInt32(session);
                break;

            default:
                length--;
                break;
            }

            var buffer = session.GetBuffer(length);

            stream.Read(buffer, 0, length);
            var res = StringEx.FromUtf8Bytes(buffer, 0, length);

            return(res);
        }
Пример #6
0
 public override object ReadValue(Stream stream, DeserializerSession session)
 {
     var size = sizeof (long);
     var buffer = session.GetBuffer(size);
     stream.Read(buffer, 0, size);
     return BitConverter.ToInt64(buffer, 0);
 }
Пример #7
0
        public override object ReadValue(Stream stream, DeserializerSession session)
        {
            var size   = sizeof(ushort);
            var buffer = session.GetBuffer(size);

            stream.Read(buffer, 0, size);
            return(BitConverter.ToUInt16(buffer, 0));
        }
Пример #8
0
        public static uint ReadUInt16(this Stream self, DeserializerSession session)
        {
            var buffer = session.GetBuffer(2);

            self.Read(buffer, 0, 2);
            var res = BitConverter.ToUInt16(buffer, 0);

            return(res);
        }
Пример #9
0
        public static int ReadInt32(this Stream self, DeserializerSession session)
        {
            var buffer = session.GetBuffer(4);

            self.Read(buffer, 0, 4);
            var res = BitConverter.ToInt32(buffer, 0);

            return(res);
        }
Пример #10
0
        public override object ReadValue(Stream stream, DeserializerSession session)
        {
            var size   = sizeof(long);
            var buffer = session.GetBuffer(size);

            stream.Read(buffer, 0, size);
            var ticks = BitConverter.ToInt64(buffer, 0);

            return(new DateTime(ticks));
        }
Пример #11
0
        public override object ReadValue(Stream stream, DeserializerSession session)
        {
            var length = stream.ReadByte();
            if (length == 0)
                return null;
            length --;

            if (length == 254)
                length = stream.ReadInt32(session);

            var buffer = session.GetBuffer(length);

            stream.Read(buffer, 0, length);
            var res = Encoding.UTF8.GetString(buffer, 0, length);
            return res;
        }
Пример #12
0
        public override object ReadValue(Stream stream, DeserializerSession session)
        {
            var bytes = session.GetBuffer(Int32Serializer.Size);

            var parts = new[]
            {
                Int32Serializer.ReadValueImpl(stream, bytes),
                Int32Serializer.ReadValueImpl(stream, bytes),
                Int32Serializer.ReadValueImpl(stream, bytes),
                Int32Serializer.ReadValueImpl(stream, bytes)
            };
            var sign = (parts[3] & 0x80000000) != 0;

            var scale = (byte) ((parts[3] >> 16) & 0x7F);
            var newValue = new decimal(parts[0], parts[1], parts[2], sign, scale);
            return newValue;
        }
Пример #13
0
        public override object ReadValue(Stream stream, DeserializerSession session)
        {
            var length = (int) Int32Serializer.Instance.ReadValue(stream, session);
            if (length == -1)
                return null;

            var buffer = session.GetBuffer(length);
            stream.Read(buffer, 0, length);
            var shortname = Encoding.UTF8.GetString(buffer, 0, length);
            var name = Utils.ToQualifiedAssemblyName(shortname);
            var type = Type.GetType(name);
            //add the deserialized type to lookup
            if (session.Serializer.Options.PreserveObjectReferences)
            {
                session.TrackDeserializedObject(type);
            }
            return type;
        }
Пример #14
0
        public override object ReadValue(Stream stream, DeserializerSession session)
        {
            var bytes = session.GetBuffer(Int32Serializer.Size);

            var parts = new[]
            {
                Int32Serializer.ReadValueImpl(stream, bytes),
                Int32Serializer.ReadValueImpl(stream, bytes),
                Int32Serializer.ReadValueImpl(stream, bytes),
                Int32Serializer.ReadValueImpl(stream, bytes)
            };
            var sign = (parts[3] & 0x80000000) != 0;

            var scale    = (byte)((parts[3] >> 16) & 0x7F);
            var newValue = new decimal(parts[0], parts[1], parts[2], sign, scale);

            return(newValue);
        }
Пример #15
0
        public static string ReadString(this Stream stream, DeserializerSession session)
        {
            var length = stream.ReadByte();
            switch (length)
            {
                case 0:
                    return null;
                case 255:
                    length = stream.ReadInt32(session);
                    break;
                default:
                    length--;
                    break;
            }

            var buffer = session.GetBuffer(length);

            stream.Read(buffer, 0, length);
            var res = StringEx.FromUtf8Bytes(buffer, 0, length);
            return res;
        }
Пример #16
0
        public override object ReadValue(Stream stream, DeserializerSession session)
        {
            var length = stream.ReadByte();

            if (length == 0)
            {
                return(null);
            }
            length--;

            if (length == 254)
            {
                length = stream.ReadInt32(session);
            }

            var buffer = session.GetBuffer(length);

            stream.Read(buffer, 0, length);
            var res = Encoding.UTF8.GetString(buffer, 0, length);

            return(res);
        }
Пример #17
0
        public override object ReadValue(Stream stream, DeserializerSession session)
        {
            var length = (int)Int32Serializer.Instance.ReadValue(stream, session);

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

            var buffer = session.GetBuffer(length);

            stream.Read(buffer, 0, length);
            var shortname = Encoding.UTF8.GetString(buffer, 0, length);
            var name      = Utils.ToQualifiedAssemblyName(shortname);
            var type      = Type.GetType(name);

            //add the deserialized type to lookup
            if (session.Serializer.Options.PreserveObjectReferences)
            {
                session.TrackDeserializedObject(type);
            }
            return(type);
        }
Пример #18
0
 public sealed override object ReadValue(Stream stream, DeserializerSession session)
 {
     return(_readCompiled(stream, session.GetBuffer(PreallocatedByteBufferSize)));
 }
Пример #19
0
 public override object ReadValue(Stream stream, DeserializerSession session)
 {
     var buffer = session.GetBuffer(16);
     stream.Read(buffer, 0, 16);
     return new Guid(buffer); //TODO: cap array?
 }