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(); } } }
public PbfBlobParser(Stream stream) { fileLength = stream.Length; reader = new ProtobufReader(stream, stream.Length); var generator = CreateMaps(); blobHeaderMapper = generator.CreateMapper <BlobHeader>(); blobMapper = generator.CreateMapper <Blob>(); }
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); }
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"); } }
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); } }
public PbfPrimitiveReader(Stream stream, long length) { this.length = length; this.reader = new ProtobufReader(stream, length); }
public T ReadMessage(ProtobufReader reader, long size) { return(ReadMessageAsync(reader, size).Result); }
public T ReadMessage(ProtobufReader reader) { return(ReadMessageAsync(reader).Result); }