Java Code Examples for com.google.protobuf.Descriptors.FieldDescriptor#getName()

The following examples show how to use com.google.protobuf.Descriptors.FieldDescriptor#getName() . 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: ProtoWriteSupport.java    From parquet-mr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
MessageWriter(Descriptor descriptor, GroupType schema) {
  List<FieldDescriptor> fields = descriptor.getFields();
  fieldWriters = (FieldWriter[]) Array.newInstance(FieldWriter.class, fields.size());

  for (FieldDescriptor fieldDescriptor: fields) {
    String name = fieldDescriptor.getName();
    Type type = schema.getType(name);
    FieldWriter writer = createWriter(fieldDescriptor, type);

    if(writeSpecsCompliant && fieldDescriptor.isRepeated() && !fieldDescriptor.isMapField()) {
      writer = new ArrayWriter(writer);
    }
    else if (!writeSpecsCompliant && fieldDescriptor.isRepeated()) {
      // the old schemas style used to write maps as repeated fields instead of wrapping them in a LIST
      writer = new RepeatedWriter(writer);
    }

    writer.setFieldName(name);
    writer.setIndex(schema.getFieldIndex(name));

    fieldWriters[fieldDescriptor.getIndex()] = writer;
  }
}
 
Example 2
Source File: DefaultRpcDataConverter.java    From krpc with Apache License 2.0 6 votes vote down vote up
Map<String, Object> getCtxMap(Builder b, WebContextData ctx, DefaultWebReq req) {

        Map<String, Object> m = null;

        for (FieldDescriptor field : b.getDescriptorForType().getFields()) {
            String name = field.getName();
            Object value = getValue(ctx, req, name);
            if (value != null) {
                if (m == null) m = new HashMap<>();
                m.put(name, value);
                req.getParameters().putIfAbsent(name,value);
            }
        }

        return m;
    }
 
Example 3
Source File: MapToMessage.java    From krpc with Apache License 2.0 6 votes vote down vote up
static public Message toMessage(Builder b, Map<String, Object> params, Map<String, Object> ctx) {
    for (FieldDescriptor field : b.getDescriptorForType().getFields()) {
        String name = field.getName();
        Object value = getValue(params, ctx, name);
        if (value == null) continue;
        if (field.isMapField()) {
            objToMap(b, field, value);
        } else if (field.isRepeated()) {
            objToMessageObjRepeated(b, value, field);
        } else {
            if (value instanceof List) {
                value = ((List) value).get(0);
                if (value == null) continue;
            }
            objToMessageObj(b, value, field);
        }
    }

    return b.build();
}
 
Example 4
Source File: MapToMessage.java    From krpc with Apache License 2.0 6 votes vote down vote up
static Builder getFieldBuilder(Builder b, FieldDescriptor f) {

        try {
            if(  b instanceof MapEntry.Builder ) {
                 MapEntry.Builder bb = (MapEntry.Builder)b;
                 return bb.newBuilderForField(f);
            }

            String fieldName = f.getName();
            String methodName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1) + "Builder";
            Method method = b.getClass().getDeclaredMethod(methodName, dummyTypes);
            Builder builder = (Builder) method.invoke(b, dummyParameters);
            return builder;
        } catch (Exception e) {
            throw new RuntimeException("getFieldBuilder exception", e);
        }
    }
 
Example 5
Source File: ProtobufDecompiler.java    From sql-layer with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void decompileOptions(MessageOrBuilder options) throws IOException {
    for (Map.Entry<FieldDescriptor,Object> entry : options.getAllFields().entrySet()) {
        FieldDescriptor field = entry.getKey();
        Object value = entry.getValue();
        String fieldName = field.getName();
        if (field.isExtension()) {
            fieldName = "(" + fieldName + ")";
        }
        if (field.getType() == FieldDescriptor.Type.MESSAGE) {
            for (Map.Entry<FieldDescriptor,Object> subentry : ((MessageOrBuilder)value).getAllFields().entrySet()) {
                FieldDescriptor subfield = subentry.getKey();
                Object subvalue = subentry.getValue();
                indentedFormat("option %s.%s = %s;", fieldName, subfield.getName(), literal(subvalue, subfield.getType()));
            }
        }
        else {
            indentedFormat("option %s = %s;", fieldName, literal(value, field.getType()));
        }
    }
}
 
Example 6
Source File: SimpleRpcDispatcher.java    From fuchsia with Apache License 2.0 5 votes vote down vote up
/**
 * Find out which method to call on the service bean.
 */
protected Method resolveTargetMethod(Message message,
                                     FieldDescriptor payloadField) {
    Method targetMethod = fieldToMethod.get(payloadField);

    if (targetMethod == null) {
        // look up and cache target method; this block is called only once
        // per target method, so synchronized is ok
        synchronized (this) {
            targetMethod = fieldToMethod.get(payloadField);
            if (targetMethod == null) {
                String name = payloadField.getName();
                for (Method method : service.getClass().getMethods()) {
                    if (method.getName().equals(name)) {
                        try {
                            method.setAccessible(true);
                        } catch (Exception ex) {
                            log.log(Level.SEVERE,"Error accessing RPC method",ex);
                        }

                        targetMethod = method;
                        fieldToMethod.put(payloadField, targetMethod);
                        break;
                    }
                }
            }
        }
    }

    if (targetMethod != null) {
        return targetMethod;
    } else {
        throw new RuntimeException("No matching method found by the name '"
                + payloadField.getName() + "'");
    }
}
 
Example 7
Source File: ProtoWriteSupport.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
/** validates mapping between protobuffer fields and parquet fields.*/
private void validatedMapping(Descriptor descriptor, GroupType parquetSchema) {
  List<FieldDescriptor> allFields = descriptor.getFields();

  for (FieldDescriptor fieldDescriptor: allFields) {
    String fieldName = fieldDescriptor.getName();
    int fieldIndex = fieldDescriptor.getIndex();
    int parquetIndex = parquetSchema.getFieldIndex(fieldName);
    if (fieldIndex != parquetIndex) {
      String message = "FieldIndex mismatch name=" + fieldName + ": " + fieldIndex + " != " + parquetIndex;
      throw new IncompatibleSchemaModificationException(message);
    }
  }
}
 
Example 8
Source File: Gpb4JUtil.java    From Okra with Apache License 2.0 5 votes vote down vote up
public Object[] covertGpb2ObjArray(Message message) {
    Map<FieldDescriptor, Object> fields = message.getAllFields();
    Object[] objects = new Object[fields.size()];
    for (Map.Entry<FieldDescriptor, Object> entry : fields.entrySet()) {
        FieldDescriptor fieldDescriptor = entry.getKey();
        String name = fieldDescriptor.getName();



    }
    return objects;
}
 
Example 9
Source File: ChangeSetHelper.java    From sql-layer with GNU Affero General Public License v3.0 5 votes vote down vote up
private static void requiredFields(Message msg, int... fields) {
    for(int fieldNumber : fields) {
        FieldDescriptor field = msg.getDescriptorForType().findFieldByNumber(fieldNumber);
        if(!msg.hasField(field)) {
            throw new IllegalArgumentException("Missing field: " + field.getName());
        }
    }
}
 
Example 10
Source File: ProtoReflection.java    From bundletool with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the {@link Class} object corresponding to the given message field.
 *
 * <p>If the field is repeated, then returns the class of the single item, rather than the
 * collection class.
 */
@SuppressWarnings("unchecked") // The unchecked cast is executed for proto message field only.
public static <T extends Message> Class<? extends Message> getJavaClassOfMessageField(
    T message, FieldDescriptor field) {
  checkArgument(field.getType().getJavaType().equals(JavaType.MESSAGE));

  if (field.isRepeated()) {
    String fieldGetterName = getterNameForProtoField(field);
    try {
      Method fieldGetter = message.getClass().getMethod(fieldGetterName);
      ParameterizedType fieldTypeArg = (ParameterizedType) fieldGetter.getGenericReturnType();
      checkState(
          fieldTypeArg.getActualTypeArguments().length == 1,
          "Collection representing a repeated field should have exactly one type argument.");
      return (Class<? extends Message>) fieldTypeArg.getActualTypeArguments()[0];
    } catch (NoSuchMethodException e) {
      throw new RuntimeException(
          "Failed to resolve getter of repeated field "
              + field.getName()
              + " in proto "
              + message.getClass().getName(),
          e);
    }
  } else {
    return (Class<? extends Message>) message.getField(field).getClass();
  }
}
 
Example 11
Source File: FieldMasks.java    From google-ads-java with Apache License 2.0 5 votes vote down vote up
private static String getFieldName(String currentField, FieldDescriptor field) {
  if (currentField.isEmpty()) {
    return field.getName();
  } else {
    return currentField + "." + field.getName();
  }
}
 
Example 12
Source File: MetaDataEvolutionValidator.java    From fdb-record-layer with Apache License 2.0 5 votes vote down vote up
private void validateTypeChange(@Nonnull FieldDescriptor oldFieldDescriptor, @Nonnull FieldDescriptor newFieldDescriptor) {
    // Allowed changes: Going from a variable length 32 bit integer to a variable length 64 bit integer
    // Other changes either change the Protobuf or the Tuple serialization of the field or can lead to a loss of precision.
    if (!(oldFieldDescriptor.getType().equals(FieldDescriptor.Type.INT32) && newFieldDescriptor.getType().equals(FieldDescriptor.Type.INT64)) &&
            !(oldFieldDescriptor.getType().equals(FieldDescriptor.Type.SINT32) && newFieldDescriptor.getType().equals(FieldDescriptor.Type.SINT64))) {
        throw new MetaDataException("field type changed",
                LogMessageKeys.FIELD_NAME, oldFieldDescriptor.getName(),
                LogMessageKeys.OLD_FIELD_TYPE, oldFieldDescriptor.getType(),
                LogMessageKeys.NEW_FIELD_TYPE, newFieldDescriptor.getType());
    }
}
 
Example 13
Source File: MetaDataEvolutionValidator.java    From fdb-record-layer with Apache License 2.0 5 votes vote down vote up
private void validateField(@Nonnull FieldDescriptor oldFieldDescriptor, @Nonnull FieldDescriptor newFieldDescriptor,
                           @Nonnull Set<Pair<Descriptor, Descriptor>> seenDescriptors) {
    if (!oldFieldDescriptor.getName().equals(newFieldDescriptor.getName())) {
        // TODO: Field renaming should be allowed with some caveats about if the field is indexed or not
        throw new MetaDataException("field renamed",
                LogMessageKeys.OLD_FIELD_NAME, oldFieldDescriptor.getName(),
                LogMessageKeys.NEW_FIELD_NAME, newFieldDescriptor.getName());
    }
    if (!oldFieldDescriptor.getType().equals(newFieldDescriptor.getType())) {
        validateTypeChange(oldFieldDescriptor, newFieldDescriptor);
    }
    if (oldFieldDescriptor.isRequired() && !newFieldDescriptor.isRequired()) {
        throw new MetaDataException("required field is no longer required",
                LogMessageKeys.FIELD_NAME, oldFieldDescriptor.getName());
    } else if (oldFieldDescriptor.isOptional() && !newFieldDescriptor.isOptional()) {
        // TODO: In theory, optional -> repeated is okay, but only if the field is not indexed
        throw new MetaDataException("optional field is no longer optional",
                LogMessageKeys.FIELD_NAME, oldFieldDescriptor.getName());
    } else if (oldFieldDescriptor.isRepeated() && !newFieldDescriptor.isRepeated()) {
        throw new MetaDataException("repeated field is no longer repeated",
                LogMessageKeys.FIELD_NAME, oldFieldDescriptor.getName());
    }
    if (oldFieldDescriptor.getType().equals(FieldDescriptor.Type.ENUM)) {
        validateEnum(newFieldDescriptor.getName(), oldFieldDescriptor.getEnumType(), newFieldDescriptor.getEnumType());
    }
    if (oldFieldDescriptor.getType().equals(FieldDescriptor.Type.GROUP) || oldFieldDescriptor.getType().equals(FieldDescriptor.Type.MESSAGE)) {
        // Message types need to be validated against each other as well.
        final Descriptor oldMessageType = oldFieldDescriptor.getMessageType();
        final Descriptor newMessageType = newFieldDescriptor.getMessageType();
        validateMessage(oldMessageType, newMessageType, seenDescriptors);
    }
}
 
Example 14
Source File: MetaDataEvolutionValidator.java    From fdb-record-layer with Apache License 2.0 4 votes vote down vote up
/**
 * Validate that the record types have all been evolved in a legal way. In particular, this makes sure that
 * each record type defined in the union descriptor is in the new union descriptor in the correct
 * place. It will then verify that each message type has been updated in a legal way, i.e., that it only
 * includes new fields.
 *
 * @param oldUnionDescriptor the union descriptor for the existing meta-data for some record store
 * @param newUnionDescriptor the new proposed meta-data
 */
@SuppressWarnings("PMD.CompareObjectsWithEquals")
public void validateUnion(@Nonnull Descriptor oldUnionDescriptor, @Nonnull Descriptor newUnionDescriptor) {
    if (oldUnionDescriptor == newUnionDescriptor) {
        // Don't bother validating the record types if they are all the same.
        return;
    }
    final BiMap<Descriptor, Descriptor> updatedDescriptors = HashBiMap.create(oldUnionDescriptor.getFields().size());
    final Set<Pair<Descriptor, Descriptor>> seenDescriptors = new HashSet<>();

    for (FieldDescriptor oldUnionField : oldUnionDescriptor.getFields()) {
        if (!oldUnionField.getType().equals(FieldDescriptor.Type.MESSAGE)) {
            throw new MetaDataException("field in union is not a message type", LogMessageKeys.FIELD_NAME, oldUnionField.getName());
        }
        int fieldNumber = oldUnionField.getNumber();
        FieldDescriptor newUnionField = newUnionDescriptor.findFieldByNumber(fieldNumber);
        if (newUnionField != null) {
            if (!newUnionField.getType().equals(FieldDescriptor.Type.MESSAGE)) {
                throw new MetaDataException("field in new union is not a message type", LogMessageKeys.FIELD_NAME, newUnionField.getName());
            }
            Descriptor oldRecord = oldUnionField.getMessageType();
            Descriptor newRecord = newUnionField.getMessageType();

            // Verify that all fields of the same type in the old union are also of the same type
            // in the new union (i.e., that there are no "splits" or "merges" of record types).
            Descriptor alreadySeenNewRecord = updatedDescriptors.get(oldRecord);
            if (alreadySeenNewRecord != null) {
                if (alreadySeenNewRecord != newRecord) {
                    // A "split" -- the same type in the old union points to two different types in the new union
                    throw new MetaDataException("record type corresponds to multiple types in new meta-data",
                            LogMessageKeys.OLD_RECORD_TYPE, oldRecord.getName(),
                            LogMessageKeys.NEW_RECORD_TYPE, newRecord.getName() + " & " + alreadySeenNewRecord.getName());
                }
            } else {
                if (updatedDescriptors.containsValue(newRecord)) {
                    // A "merge" -- two different types in the old union point to the same type in the new union
                    final Descriptor alreadySeenOldRecord = updatedDescriptors.inverse().get(newRecord);
                    throw new MetaDataException("record type corresponds to multiple types in old meta-data",
                            LogMessageKeys.OLD_RECORD_TYPE, oldRecord.getName() + " & " + alreadySeenOldRecord.getName(),
                            LogMessageKeys.NEW_RECORD_TYPE, newRecord.getName());
                }
            }
            updatedDescriptors.put(oldRecord, newRecord);

            // Validate the form of the old and new record types
            validateMessage(oldRecord, newRecord, seenDescriptors);
        } else {
            throw new MetaDataException("record type removed from union", LogMessageKeys.RECORD_TYPE, oldUnionField.getMessageType());
        }
    }
}
 
Example 15
Source File: JdbcProtobufTemplate.java    From jigsaw-payment with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * @param message
 * @param conditionFields
 * @param conditionParams
 * @param tableName
 * @return
 */
protected int updateMessageByCondition(M message, String[] conditionFields,
		Object[] conditionParams, String tableName) {
	StringBuilder updateSql = new StringBuilder("update ");
	updateSql.append(tableName).append(" set ");
	StringBuilder options = new StringBuilder("");
	List<Object> args = new ArrayList<Object>();
	Map<FieldDescriptor, Object> fieldMap = message.getAllFields();

	for (Entry<FieldDescriptor, Object> entry : fieldMap.entrySet()) {
		FieldDescriptor fieldDescriptor = entry.getKey();
		if (!Arrays.asList(conditionFields).contains(
				fieldDescriptor.getName())) {
			FieldOptions fieldOptions = fieldDescriptor.getOptions();
			ColumnFieldOption columnFieldOption = fieldOptions
					.getExtension(Taglib.columnOption);
			String fieldName = fieldDescriptor.getName();
			Object value = entry.getValue();
			if (columnFieldOption.getColumnType() == ColumnType.DATETIME
					|| columnFieldOption.getColumnType() == ColumnType.TIMESTAMP) {// datetime类型
				if (value != null && (long) value > 0) {
					options.append(fieldName).append("=?, ");
					args.add(new Timestamp((long) value));
				}
			} else {
				options.append(fieldName).append("=?, ");
				args.add(value);
			}
		}
	}
	int tmpIndex = options.lastIndexOf(",");
	updateSql.append(options.substring(0, tmpIndex)).append(" where 1=1 ");
	StringBuilder condition = new StringBuilder();
	if (conditionFields.length != conditionParams.length) {
		throw new IllegalArgumentException("condition error");
	} else {
		for (int i = 0; i < conditionFields.length; i++) {
			condition.append("AND ").append(conditionFields[i])
					.append("=? ");
			args.add(conditionParams[i]);
		}
		updateSql.append(condition);
		String sql = updateSql.toString();
		logger.debug(sql);
		return update(sql, args);
	}
}
 
Example 16
Source File: GqlInputConverter.java    From rejoiner with Apache License 2.0 4 votes vote down vote up
/** Field names with under_scores are converted to camelCase. */
private static String getFieldName(FieldDescriptor field) {
  String fieldName = field.getName();
  return fieldName.contains("_") ? UNDERSCORE_TO_CAMEL.convert(fieldName) : fieldName;
}
 
Example 17
Source File: ProtoTruthMessageDifferencer.java    From curiostack with MIT License 4 votes vote down vote up
private static String name(FieldDescriptor fieldDescriptor) {
  return fieldDescriptor.isExtension() ? "[" + fieldDescriptor + "]" : fieldDescriptor.getName();
}
 
Example 18
Source File: MessageToMap.java    From krpc with Apache License 2.0 4 votes vote down vote up
static void parseSingleField(FieldDescriptor field, Object value, Map<String, Object> results, boolean isArray, boolean withDefault, int maxRepeatedSizeToGet) {

        String name = field.getName();

        switch (field.getType()) {
            case INT32:
            case SINT32:
            case SFIXED32:
                addToResults(name,value, results, isArray);
                break;

            case INT64:
            case SINT64:
            case SFIXED64:
                addToResults(name,value, results, isArray);
                break;

            case BOOL:
                addToResults(name,value, results, isArray);
                break;

            case FLOAT:
                addToResults(name,value, results, isArray);
                break;

            case DOUBLE:
                addToResults(name,value, results, isArray);
                break;

            case UINT32:
            case FIXED32:
                addToResults(name, unsignedToLong((Integer) value), results, isArray);
                break;

            case UINT64:
            case FIXED64:
                addToResults(name, unsignedToBigInteger((Long) value), results, isArray);
                break;

            case STRING:
                addToResults(name,value, results, isArray);
                break;

            case BYTES: {
                if (value instanceof ByteString) {
                    addToResults(name, value, results, isArray);
                }
                if (value instanceof String) {
                    byte[] bb = getBytes((String) value);
                    if (bb != null) {
                        addToResults(name, ByteString.copyFrom(bb), results, isArray);
                    }
                }
                if (value instanceof byte[]) {
                    addToResults(name, ByteString.copyFrom((byte[]) value), results, isArray);
                }
            }
            break;

            case ENUM:
                addToResults(name, ((EnumValueDescriptor) value).getNumber(), results, isArray);
                break;

            case MESSAGE:
                HashMap<String, Object> sub = new LinkedHashMap<>();
                parseMessage((Message) value, sub, withDefault, maxRepeatedSizeToGet);
                addToResults(name, sub, results, isArray);
                break;

            default:
                break;
        }
    }
 
Example 19
Source File: ProtobufDecompiler.java    From sql-layer with GNU Affero General Public License v3.0 4 votes vote down vote up
protected String defaultAndOptions(MessageOrBuilder options, String defaultValue) {
    StringBuilder str = new StringBuilder();
    boolean first = true;
    if (defaultValue != null) {
        str.append(" [default = ");
        str.append(defaultValue); // TODO: quote
        first = false;
    }
    if (options != null) {
        for (Map.Entry<FieldDescriptor,Object> entry : options.getAllFields().entrySet()) {
            FieldDescriptor field = entry.getKey();
            Object value = entry.getValue();
            String fieldName = field.getName();
            if (field.isExtension()) {
                fieldName = "(" + fieldName + ")";
            }
            if (field.getType() == FieldDescriptor.Type.MESSAGE) {
                for (Map.Entry<FieldDescriptor,Object> subentry : ((MessageOrBuilder)value).getAllFields().entrySet()) {
                    FieldDescriptor subfield = subentry.getKey();
                    Object subvalue = subentry.getValue();
                    if (first) {
                        str.append(" [");
                        first = false;
                    }
                    else {
                        str.append(", ");
                    }
                    str.append(fieldName).append(".").append(subfield.getName()).append(" = ").append(literal(subvalue, subfield.getType()));
                }
            }
            else {
                if (first) {
                    str.append(" [");
                    first = false;
                }
                else {
                    str.append(", ");
                }
                str.append(fieldName).append(" = ").append(literal(value, field.getType()));
            }
        }
    }
    if (!first) {
        str.append("]");
    }
    return str.toString();
}
 
Example 20
Source File: MapToMessage.java    From krpc with Apache License 2.0 4 votes vote down vote up
static Object objToMessageObjInner(Builder b, Object value, FieldDescriptor field, boolean isRepeated) {

        switch (field.getType()) {
            case INT32:
            case SINT32:
            case SFIXED32:
                return TypeSafe.anyToInt(value);

            case INT64:
            case SINT64:
            case SFIXED64:
                if( value instanceof Date)
                    return ((Date)value).getTime();
                return TypeSafe.anyToLong(value);

            case BOOL:
                return TypeSafe.anyToBool(value);

            case FLOAT:
                return TypeSafe.anyToFloat(value);

            case DOUBLE:
                return TypeSafe.anyToDouble(value);

            case UINT32:
            case FIXED32:
                return (int) (TypeSafe.anyToLong(value) & 0x00000000FFFFFFFFL);

            case UINT64:
            case FIXED64:
                BigInteger bi = new BigInteger(value.toString());
                return bi.longValue();

            case STRING:
                if( value instanceof Date)
                    return formatDate((Date)value);
                return TypeSafe.anyToString(value);

            case BYTES: {
                    if (value instanceof ByteString) {
                        return value;
                    }
                    if (value instanceof String) {
                        byte[] bb = getBytes((String) value);
                        if (bb == null) return null;
                        return ByteString.copyFrom(bb);
                    }
                    if (value instanceof byte[]) {
                        return ByteString.copyFrom((byte[]) value);
                    }

                    return null;
                }

            case ENUM: {
                    EnumDescriptor ed = field.getEnumType();
                    EnumValueDescriptor evd = ed.findValueByName(value.toString());
                    if (evd == null) {
                        evd = ed.findValueByNumber(TypeSafe.anyToInt(value));
                    }
                    if (evd == null) return null;
                    return evd;
                }

            case MESSAGE:

                Map<String, Object> map = TypeSafe.anyToMap(value);
                if (map == null) {
                    if( value instanceof MapConvertable) {
                        map = ((MapConvertable)value).toMap();
                    }
                    if( map == null ) {
                        return null;
                    }
                }

                Builder b2 = isRepeated ?
                        getRepeatedFieldBuilder(b, field.getName()) :
                                getFieldBuilder(b, field);

                for (FieldDescriptor subfield : b2.getDescriptorForType().getFields()) {
                    String subName = subfield.getName();
                    Object subValue = getValue(map, null, subName);
                    if (subValue == null) continue;
                    if (subfield.isRepeated()) {
                        objToMessageObjRepeated(b2, subValue, subfield);
                    } else {
                        objToMessageObj(b2, subValue, subfield);
                    }
                }

                return isRepeated ? null : b2.build();

            default:
                return null;
        }
    }