示例#1
0
        public void StringInUtf8CanBeReaded()
        {
            // Arrange
            const string s         = "hello world";
            var          data      = Encoding.UTF8.GetBytes(s);
            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.ReadUtf8WithSizePrefix();

            // Assert
            result.Should().Be(s);
            stream.Offset.Should().Be(finalData.Count);
        }
示例#2
0
 protected override string DeserializeInternal(DeserializationStream stream, Type sourceType)
 {
     return(stream.ReadUtf8WithSizePrefix());
 }
示例#3
0
        protected override Uri DeserializeInternal(DeserializationStream stream, Type sourceType)
        {
            string absoluteUri = stream.ReadUtf8WithSizePrefix();

            return(new Uri(absoluteUri));
        }