Java Code Examples for com.google.protobuf.DescriptorProtos.FieldDescriptorProto#newBuilder()
The following examples show how to use
com.google.protobuf.DescriptorProtos.FieldDescriptorProto#newBuilder() .
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: DescriptorGenerator.java From api-compiler with Apache License 2.0 | 5 votes |
private FieldDescriptorProto generateField(Field field) { FieldDescriptorProto.Builder builder = FieldDescriptorProto.newBuilder(); builder.setName(getFieldName(field)); builder.setNumber(field.getNumber()); builder.setLabel(toLabel(field.getCardinality())); builder.setType(toType(field.getKind())); if (field.getKind() == Kind.TYPE_ENUM || field.getKind() == Kind.TYPE_MESSAGE || field.getKind() == Kind.TYPE_GROUP) { builder.setTypeName(getTypeName(field.getTypeUrl())); } // NOTE: extendee not supported // NOTE: default_value not supported if (field.getOneofIndex() != 0) { // Index in the containing type's oneof_decl is zero-based. // Index in google.protobuf.type.Field.oneof_index is one-based. builder.setOneofIndex(field.getOneofIndex() - 1); } if (!Strings.isNullOrEmpty(field.getDefaultValue())) { builder.setDefaultValue(field.getDefaultValue()); } FieldOptions options = getFieldOptions(field); if (!options.equals(FieldOptions.getDefaultInstance())) { builder.setOptions(options); } return builder.build(); }
Example 2
Source File: MessageDefinition.java From protobuf-dynamic with Apache License 2.0 | 5 votes |
private void addField(FieldDescriptorProto.Label label, String type, String name, int num, String defaultVal, OneofBuilder oneofBuilder) { FieldDescriptorProto.Builder fieldBuilder = FieldDescriptorProto.newBuilder(); fieldBuilder.setLabel(label); FieldDescriptorProto.Type primType = sTypeMap.get(type); if (primType != null) fieldBuilder.setType(primType); else fieldBuilder.setTypeName(type); fieldBuilder.setName(name).setNumber(num); if (defaultVal != null) fieldBuilder.setDefaultValue(defaultVal); if (oneofBuilder != null) fieldBuilder.setOneofIndex(oneofBuilder.getIdx()); mMsgTypeBuilder.addField(fieldBuilder.build()); }