Java Code Examples for com.baidu.bjf.remoting.protobuf.Codec#getDescriptor()

The following examples show how to use com.baidu.bjf.remoting.protobuf.Codec#getDescriptor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DescritporTest.java    From jprotobuf with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetDescriptor() throws IOException {
    Descriptor descriptor2 = AddressBookProtos.AddressBook.getDescriptor();

    FieldDescriptor stringMapFD = descriptor2.findFieldByName("person");
    byte[] bytes = getProtoBytes2();
    DynamicMessage parseFrom = DynamicMessage.parseFrom(descriptor2, bytes);
    Object field = parseFrom.getField(stringMapFD);
    Assert.assertTrue(field instanceof List);
    
    Codec<AddressBookProtosPOJO> codec = ProtobufProxy.create(AddressBookProtosPOJO.class, true);
    Descriptor descriptor = codec.getDescriptor();
    
    stringMapFD = descriptor.findFieldByName("list");

    bytes = getProtoBytes2();

    parseFrom = DynamicMessage.parseFrom(descriptor, bytes);

    Object field2 = parseFrom.getField(stringMapFD);
    Assert.assertTrue(field2 instanceof List);

}
 
Example 2
Source File: SimpleMapTest.java    From jprotobuf with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetDescriptor() throws IOException {
    Codec<SimpleMapPOJO> codec = ProtobufProxy.create(SimpleMapPOJO.class, false);

    Descriptor descriptor = codec.getDescriptor();
    
    String escapeBytes = StringUtils.escapeBytes(descriptor.toProto().toByteArray());
    System.out.println(escapeBytes);

    FieldDescriptor stringMapFD = descriptor.findFieldByName("stringMap");

    byte[] bytes = getProtoBytes2();

    DynamicMessage parseFrom = DynamicMessage.parseFrom(descriptor, bytes);

    Object field = parseFrom.getField(stringMapFD);
    Assert.assertTrue(field instanceof List);
    Assert.assertEquals(2, ((List) field).size());
    
    Descriptor descriptor2 = AddressBookProtos.Person.getDescriptor();
    
    stringMapFD = descriptor2.findFieldByName("stringMap");
    bytes = getProtoBytes2();
    parseFrom = DynamicMessage.parseFrom(descriptor2, bytes);
    field = parseFrom.getField(stringMapFD);
    Assert.assertTrue(field instanceof List);
    Assert.assertEquals(2, ((List) field).size());

}