/** In proto3, repeated fields of scalar numeric types use packed encoding by default */ private boolean isDefaultPackedEncoding(Field field) { if (field.getSyntax() == Syntax.SYNTAX_PROTO3 && field.isRepeated()) { FieldDescriptorProto.Type fieldType = field.getProto().getType(); if (fieldType != FieldDescriptorProto.Type.TYPE_GROUP && fieldType != FieldDescriptorProto.Type.TYPE_BYTES && fieldType != FieldDescriptorProto.Type.TYPE_STRING && fieldType != FieldDescriptorProto.Type.TYPE_MESSAGE) { return true; } } return false; }
/** In proto3, repeated fields of scalar numeric types use packed encoding by default */ private boolean isDefaultPackedEncoding(Field field) { if (field.getSyntax() == Syntax.SYNTAX_PROTO3 && field.isRepeated()) { FieldDescriptorProto.Type fieldType = field.getProto().getType(); if (fieldType != FieldDescriptorProto.Type.TYPE_GROUP && fieldType != FieldDescriptorProto.Type.TYPE_BYTES && fieldType != FieldDescriptorProto.Type.TYPE_STRING && fieldType != FieldDescriptorProto.Type.TYPE_MESSAGE) { return true; } } return false; }
@VisitsBefore void visit(Field field) { // Resolve type of this field. TypeRef type = resolveType(field.getLocation(), field.getProto().getType(), field.getProto().getTypeName()); if (type != null) { if (field.isRepeated()) { type = type.makeRepeated(); } else if (!field.isOptional()) { type = type.makeRequired(); } field.setType(type); } // Check for resolution of oneof. if (field.getProto().hasOneofIndex() && field.getOneof() == null) { // Indicates the oneof index could not be resolved. model .getDiagReporter() .report( Diag.error( field.getLocation(), "Unresolved oneof reference (indicates internal inconsistency of input; oneof " + "index: %s)", field.getProto().getOneofIndex())); } findOptionTypes(field.getOptionFields()); }
@VisitsBefore void visit(Field field) { // Resolve type of this field. TypeRef type = resolveType(field.getLocation(), field.getProto().getType(), field.getProto().getTypeName()); if (type != null) { if (field.isRepeated()) { type = type.makeRepeated(); } else if (!field.isOptional()) { type = type.makeRequired(); } field.setType(type); } // Check for resolution of oneof. if (field.getProto().hasOneofIndex() && field.getOneof() == null) { // Indicates the oneof index could not be resolved. model .getDiagReporter() .report( Diag.error( field.getLocation(), "Unresolved oneof reference (indicates internal inconsistency of input; oneof " + "index: %s)", field.getProto().getOneofIndex())); } findOptionTypes(field.getOptionFields()); }
.setName(field.getSimpleName()) .setNumber(field.getNumber()) .setKind(toCoreFieldKind(field.getProto())) .setCardinality(toCoreFieldCardinality(field.getProto())) .setJsonName(field.getJsonName()); FieldDescriptorProto proto = field.getProto(); coreFieldBuilder.setOneofIndex(field.getProto().getOneofIndex() + 1); DescriptorNormalization.getOptions(field.getProto(), includeDefaults)); coreTypeBuilder.addFields(coreFieldBuilder.build());
.setName(field.getSimpleName()) .setNumber(field.getNumber()) .setKind(toCoreFieldKind(field.getProto())) .setCardinality(toCoreFieldCardinality(field.getProto())) .setJsonName(field.getJsonName()); FieldDescriptorProto proto = field.getProto(); coreFieldBuilder.setOneofIndex(field.getProto().getOneofIndex() + 1); DescriptorNormalization.getOptions(field.getProto(), includeDefaults)); coreTypeBuilder.addFields(coreFieldBuilder.build());