Пример #1
0
        private async Task ReadMessagePropertiesAsync(ProtobufReader reader, T message)
        {
            var num = 0;

            while (reader.State != ProtobufReaderState.EndOfMessage)
            {
                PropertyReader <T> propertyReader;
                if (propertyReaders.TryGetValue(reader.FieldNumber, out propertyReader))
                {
                    try
                    {
                        num++;
                        await propertyReader.Read(reader, message);
                    }
                    catch (Exception e)
                    {
                        throw new InvalidOperationException("", e);
                    }
                }
                else
                {
                    await reader.SkipAsync();
                }
            }
        }
Пример #2
0
        public PbfBlobParser(Stream stream)
        {
            fileLength = stream.Length;
            reader     = new ProtobufReader(stream, stream.Length);

            var generator = CreateMaps();

            blobHeaderMapper = generator.CreateMapper <BlobHeader>();
            blobMapper       = generator.CreateMapper <Blob>();
        }
Пример #3
0
        public async Task <T> ReadMessageAsync(ProtobufReader reader, long size)
        {
            var message = new T();
            await reader.BeginReadMessageAsync(size);

            await ReadMessagePropertiesAsync(reader, message);

            await reader.EndReadMessageAsync();

            return(message);
        }
Пример #4
0
        public void TestStringRead()
        {
            var bytes = new byte[] { 0x12, 0x07, 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67 };

            using (var stream = new MemoryStream(bytes))
            {
                var reader = new ProtobufReader(stream, stream.Length);
                reader.BeginReadMessage(stream.Length);
                reader.FieldNumber.Should().Be(2);
                reader.FieldType.Should().Be(FieldTypes.LengthDelimited);
                var value = reader.ReadString();
                value.Should().Be("testing");
            }
        }
Пример #5
0
        public void TestInt32Read()
        {
            var bytes = new byte[] { 0x08, 0x96, 0x01 };

            using (var stream = new MemoryStream(bytes))
            {
                var reader = new ProtobufReader(stream, stream.Length);
                reader.BeginReadMessage(stream.Length);
                reader.FieldNumber.Should().Be(1);
                reader.FieldType.Should().Be(FieldTypes.VarInt);
                var value = reader.ReadInt32();
                value.Should().Be(150);
            }
        }
Пример #6
0
 public PbfPrimitiveReader(Stream stream, long length)
 {
     this.length = length;
     this.reader = new ProtobufReader(stream, length);
 }
Пример #7
0
 public T ReadMessage(ProtobufReader reader, long size)
 {
     return(ReadMessageAsync(reader, size).Result);
 }
Пример #8
0
 public T ReadMessage(ProtobufReader reader)
 {
     return(ReadMessageAsync(reader).Result);
 }