Search in sources :

Example 1 with GeneratedMessage

use of com.google.protobuf.GeneratedMessage in project j2objc by google.

the class CompatibilityTest method testGetAllFields.

public void testGetAllFields() throws Exception {
    GeneratedMessage data = TypicalData.newBuilder().setMyInt(1).addRepeatedInt32(2).setExtension(Typical.myExtension, TypicalDataMessage.getDefaultInstance()).setExtension(Typical.myPrimitiveExtension, 3).build();
    Map<FieldDescriptor, Object> allFields = data.getAllFields();
    assertEquals(4, allFields.size());
    assertNotNull(allFields.get(Typical.myExtension.getDescriptor()));
    assertEquals(4, data.toBuilder().getAllFields().size());
    Descriptor descriptor = TypicalData.Builder.getDescriptor();
    FieldDescriptor intField = descriptor.findFieldByNumber(1);
    assertEquals(1, allFields.get(intField));
    assertEquals(3, allFields.get(Typical.myPrimitiveExtension.getDescriptor()));
}
Also used : Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) EnumDescriptor(com.google.protobuf.Descriptors.EnumDescriptor) EnumValueDescriptor(com.google.protobuf.Descriptors.EnumValueDescriptor) GeneratedMessage(com.google.protobuf.GeneratedMessage) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 2 with GeneratedMessage

use of com.google.protobuf.GeneratedMessage in project j2objc by google.

the class CompatibilityTest method testGetSerializedSize.

public void testGetSerializedSize() throws Exception {
    GeneratedMessage data = TypicalData.newBuilder().setMyInt(1).build();
    assertEquals(2, data.getSerializedSize());
}
Also used : GeneratedMessage(com.google.protobuf.GeneratedMessage)

Aggregations

GeneratedMessage (com.google.protobuf.GeneratedMessage)2 Descriptor (com.google.protobuf.Descriptors.Descriptor)1 EnumDescriptor (com.google.protobuf.Descriptors.EnumDescriptor)1 EnumValueDescriptor (com.google.protobuf.Descriptors.EnumValueDescriptor)1 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)1