Search in sources :

Example 31 with DynamicMessage

use of com.google.protobuf.DynamicMessage in project druid by druid-io.

the class SchemaRegistryBasedProtobufBytesDecoderTest method testParse.

@Test
public void testParse() throws Exception {
    Mockito.when(registry.getSchemaById(ArgumentMatchers.eq(1234))).thenReturn(parseProtobufSchema());
    ProtoTestEventWrapper.ProtoTestEvent event = getTestEvent();
    byte[] bytes = event.toByteArray();
    ByteBuffer bb = ByteBuffer.allocate(bytes.length + 6).put((byte) 0).putInt(1234).put((byte) 0).put(bytes);
    bb.rewind();
    // When
    DynamicMessage actual = new SchemaRegistryBasedProtobufBytesDecoder(registry).parse(bb);
    // Then
    Assert.assertEquals(actual.getField(actual.getDescriptorForType().findFieldByName("id")), event.getId());
}
Also used : DynamicMessage(com.google.protobuf.DynamicMessage) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

DynamicMessage (com.google.protobuf.DynamicMessage)31 Test (org.junit.Test)13 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)12 ByteString (com.google.protobuf.ByteString)11 Descriptor (com.google.protobuf.Descriptors.Descriptor)9 Message (com.google.protobuf.Message)6 IOException (java.io.IOException)6 List (java.util.List)6 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)5 Map (java.util.Map)4 TableRow (com.google.api.services.bigquery.model.TableRow)3 EnumValueDescriptor (com.google.protobuf.Descriptors.EnumValueDescriptor)3 Builder (com.google.protobuf.DynamicMessage.Builder)3 ByteBuffer (java.nio.ByteBuffer)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 DataHandler (javax.activation.DataHandler)3 Nullable (javax.annotation.Nullable)3 Descriptors (com.google.protobuf.Descriptors)2 JsonFormat (com.google.protobuf.util.JsonFormat)2