Java Code Examples for com.google.protobuf.Descriptors.FieldDescriptor#Type
The following examples show how to use
com.google.protobuf.Descriptors.FieldDescriptor#Type .
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: CompatibilityTest.java From j2objc with Apache License 2.0 | 6 votes |
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()); } }
Example 2
Source File: ProtobufDecompiler.java From sql-layer with GNU Affero General Public License v3.0 | 5 votes |
protected String literal(Object value, FieldDescriptor.Type type) { switch (type) { case STRING: return quotedString((String)value); default: return value.toString(); } }
Example 3
Source File: DescriptorsTest.java From travelguide with Apache License 2.0 | 5 votes |
public void testFieldTypeEnumMapping() throws Exception { assertEquals(FieldDescriptor.Type.values().length, FieldDescriptorProto.Type.values().length); for (FieldDescriptor.Type type : FieldDescriptor.Type.values()) { FieldDescriptorProto.Type protoType = type.toProto(); assertEquals("TYPE_" + type.name(), protoType.name()); assertEquals(type, FieldDescriptor.Type.valueOf(protoType)); } }
Example 4
Source File: DescriptorsTest.java From travelguide with Apache License 2.0 | 5 votes |
/** * Test that the FieldDescriptor.Type enum is the same as the * WireFormat.FieldType enum. */ public void testFieldTypeTablesMatch() throws Exception { FieldDescriptor.Type[] values1 = FieldDescriptor.Type.values(); WireFormat.FieldType[] values2 = WireFormat.FieldType.values(); assertEquals(values1.length, values2.length); for (int i = 0; i < values1.length; i++) { assertEquals(values1[i].toString(), values2[i].toString()); } }
Example 5
Source File: ProtoFieldInfo.java From curiostack with MIT License | 2 votes |
/** * Returns the {@link Type} of the actual value of this field, which for map fields is the type of * the map's value. */ FieldDescriptor.Type valueType() { return valueField().descriptor().getType(); }