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());
}
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);
}
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());
}
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());
}
}
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);
}
}
}
}
Aggregations