예제 #1
0
        protected override object DeserializeInternal(DeserializationStream stream, Type sourceType)
        {
            BinaryConverter converter = new BinaryConverter();

            byte[] keyData         = stream.ReadBytesWithSizePrefix();
            var    deserializedKey = converter.Deserialize <object>(keyData);

            byte[] valueData         = stream.ReadBytesWithSizePrefix();
            var    deserializedValue = converter.Deserialize <object>(valueData);

            var newKeyValuePair = Activator.CreateInstance(sourceType, deserializedKey, deserializedValue);

            return(newKeyValuePair);
        }
예제 #2
0
        public void ByteArrayWithLengthPrefixCanBeReaded()
        {
            // Arrange
            var data      = Encoding.UTF8.GetBytes("hello world");
            var size      = BitConverter.GetBytes(data.Length);
            var finalData = new List <byte>();

            foreach (byte b in size)
            {
                finalData.Add(b);
            }

            foreach (byte b in data)
            {
                finalData.Add(b);
            }

            // Act
            var stream = new DeserializationStream(finalData.ToArray());
            var result = stream.ReadBytesWithSizePrefix();

            // Assert
            result.Should().Equal(data);
            stream.Offset.Should().Be(finalData.Count);
        }
예제 #3
0
        public Enum DeserializeInto(DeserializationStream stream, Type type)
        {
            byte[] enumData = stream.ReadBytesWithSizePrefix();

            BinaryConverter converter       = new BinaryConverter();
            var             underlyingValue = converter.Deserialize <object>(enumData);

            return((Enum)Enum.ToObject(type, underlyingValue));
        }
 protected override byte[] DeserializeInternal(DeserializationStream stream, Type sourceType)
 {
     return(stream.ReadBytesWithSizePrefix());
 }
        protected override BigInteger DeserializeInternal(DeserializationStream stream, Type sourceType)
        {
            byte[] bigIntegerData = stream.ReadBytesWithSizePrefix();

            return(new BigInteger(bigIntegerData));
        }
예제 #6
0
        protected override Guid DeserializeInternal(DeserializationStream stream, Type sourceType)
        {
            byte[] guidData = stream.ReadBytesWithSizePrefix();

            return(new Guid(guidData));
        }