Search in sources :

Example 26 with FieldDescriptor

use of com.google.protobuf.Descriptors.FieldDescriptor in project j2objc by google.

the class CompatibilityTest method testGetMessageType.

public void testGetMessageType() throws Exception {
    Descriptor descriptor = TypicalData.Builder.getDescriptor();
    FieldDescriptor fieldDescriptor = descriptor.findFieldByNumber(11);
    Descriptor messageDescriptor = fieldDescriptor.getMessageType();
    assertNotNull(messageDescriptor);
    FieldDescriptor messageFieldDescriptor = messageDescriptor.findFieldByNumber(1);
    assertEquals(1, messageFieldDescriptor.getNumber());
}
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) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 27 with FieldDescriptor

use of com.google.protobuf.Descriptors.FieldDescriptor in project j2objc by google.

the class CompatibilityTest method testSetAndGetFieldWithFieldDescriptor.

public void testSetAndGetFieldWithFieldDescriptor() throws Exception {
    FieldDescriptor[] fields = new FieldDescriptor[19];
    Descriptor descriptor = TypicalData.Builder.getDescriptor();
    for (int i = 1; i <= 18; i++) {
        fields[i] = descriptor.findFieldByNumber(i);
    }
    TypicalData.Builder dataBuilder = TypicalData.newBuilder();
    dataBuilder.setField(fields[1], new Integer(42));
    dataBuilder.setField(fields[2], ByteString.copyFrom("foo".getBytes()));
    dataBuilder.setField(fields[3], TypicalData.EnumType.VALUE9.getValueDescriptor());
    dataBuilder.setField(fields[11], TypicalDataMessage.newBuilder().build());
    dataBuilder.setField(fields[12], Boolean.TRUE);
    dataBuilder.setField(fields[13], new Float(43.8));
    dataBuilder.setField(fields[14], new Double(44.5));
    dataBuilder.setField(fields[15], "bar");
    dataBuilder.setField(fields[16], new Integer(24));
    dataBuilder.setField(fields[17], new Long(4422));
    dataBuilder.setField(fields[18], new Long(2244));
    dataBuilder.addRepeatedField(fields[4], new Integer(72));
    dataBuilder.addRepeatedField(fields[8], "aaa");
    dataBuilder.addRepeatedField(fields[8], "bbb");
    dataBuilder.setRepeatedField(fields[8], 1, "ccc");
    ArrayList<Double> doubles = new ArrayList<Double>();
    doubles.add(1.2);
    doubles.add(3.4);
    dataBuilder.setField(fields[7], doubles);
    checkGetters(dataBuilder.build(), fields);
    checkGetters(dataBuilder, fields);
}
Also used : TypicalData(protos.TypicalData) ArrayList(java.util.ArrayList) Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) EnumDescriptor(com.google.protobuf.Descriptors.EnumDescriptor) EnumValueDescriptor(com.google.protobuf.Descriptors.EnumValueDescriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 28 with FieldDescriptor

use of com.google.protobuf.Descriptors.FieldDescriptor in project j2objc by google.

the class CompatibilityTest method testGetJavaType.

public void testGetJavaType() throws Exception {
    Descriptor descriptor = TypicalData.Builder.getDescriptor();
    FieldDescriptor intField = descriptor.findFieldByNumber(1);
    assertEquals(FieldDescriptor.JavaType.INT, intField.getJavaType());
    FieldDescriptor bytesField = descriptor.findFieldByNumber(2);
    assertEquals(FieldDescriptor.JavaType.BYTE_STRING, bytesField.getJavaType());
    FieldDescriptor booleanField = descriptor.findFieldByNumber(5);
    assertEquals(FieldDescriptor.JavaType.BOOLEAN, booleanField.getJavaType());
    FieldDescriptor stringField = descriptor.findFieldByNumber(8);
    assertEquals(FieldDescriptor.JavaType.STRING, stringField.getJavaType());
}
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) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 29 with FieldDescriptor

use of com.google.protobuf.Descriptors.FieldDescriptor in project j2objc by google.

the class CompatibilityTest method testFindFieldByNumber.

public void testFindFieldByNumber() throws Exception {
    Descriptor descriptor = TypicalData.Builder.getDescriptor();
    Collection<FieldDescriptor> fields = descriptor.getFields();
    for (FieldDescriptor field : fields) {
        FieldDescriptor.Type type = field.getType();
        int fieldId = field.getNumber();
        switch(fieldId) {
            case 1:
                assertEquals(Type.INT32, type);
                break;
            case 2:
                assertEquals(Type.BYTES, type);
                break;
            case 3:
                assertEquals(Type.ENUM, type);
                break;
        }
        FieldDescriptor result = descriptor.findFieldByNumber(fieldId);
        assertEquals(field.getNumber(), result.getNumber());
        assertEquals(field.getName(), result.getName());
    }
}
Also used : Type(com.google.protobuf.Descriptors.FieldDescriptor.Type) Descriptor(com.google.protobuf.Descriptors.Descriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) EnumDescriptor(com.google.protobuf.Descriptors.EnumDescriptor) EnumValueDescriptor(com.google.protobuf.Descriptors.EnumValueDescriptor) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 30 with FieldDescriptor

use of com.google.protobuf.Descriptors.FieldDescriptor in project j2objc by google.

the class PerformanceBenchmarks method testGetRepeatedFieldsWithDescriptors.

private static void testGetRepeatedFieldsWithDescriptors() {
    TypicalData.Builder builder = TypicalData.newBuilder();
    setAllRepeatedFields(builder, 25);
    TypicalData data = builder.build();
    List<FieldDescriptor> fields = getRepeatedFieldDescriptors();
    for (int i = 0; i < 50; i++) {
        for (int j = 0; j < 25; j++) {
            for (FieldDescriptor field : fields) {
                data.getRepeatedField(field, j);
            }
        }
    }
}
Also used : TypicalData(protos.TypicalData) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Aggregations

FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)45 Descriptor (com.google.protobuf.Descriptors.Descriptor)18 Test (org.junit.Test)14 EnumDescriptor (com.google.protobuf.Descriptors.EnumDescriptor)11 EnumValueDescriptor (com.google.protobuf.Descriptors.EnumValueDescriptor)11 BooleanFieldValidator (io.spine.validate.BooleanFieldValidator)9 ByteStringFieldValidator (io.spine.validate.ByteStringFieldValidator)9 FloatFieldValidator (io.spine.validate.FloatFieldValidator)9 LongFieldValidator (io.spine.validate.LongFieldValidator)9 StringFieldValidator (io.spine.validate.StringFieldValidator)9 TypicalData (protos.TypicalData)5 ArrayList (java.util.ArrayList)4 ByteString (com.google.protobuf.ByteString)3 ExtensionRegistry (com.google.protobuf.ExtensionRegistry)3 ValidationResult (io.spine.server.event.enrich.ReferenceValidator.ValidationResult)3 Map (java.util.Map)3 GeneratedMessage (com.google.protobuf.GeneratedMessage)2 Collection (java.util.Collection)2 TypicalDataMessage (protos.TypicalDataMessage)2 ImageAnnotatorClient (com.google.cloud.vision.spi.v1.ImageAnnotatorClient)1