public AbstractWriters(Field protoField, Class<T[]> arrayClass) { this.protoField = protoField; int wireType = ProtoUtils.isPacked(protoField) && protoField.isRepeated() ? WireFormat.WIRETYPE_LENGTH_DELIMITED : FieldTypeUtils.convert(protoField.getType()).wireType; this.tag = WireFormat.makeTag(protoField.getTag(), wireType); this.tagSize = ProtobufOutputEx.computeRawVarint32Size(tag); if (arrayClass == null) { arrayClass = getFieldArgument(this.getClass(), "arrayWriter"); } this.arrayClass = arrayClass; }
private void messageToString(Message message, StringBuilder sb) { commentsToString(message.getCommentLines(), sb, 0); appendLine(sb, "message %s {", message.getName()); for (Field field : message.getFields()) { sb.append(" "); fieldToString(field, field.isRepeated(), sb); } appendLine(sb, "}\n"); }
public FieldSchema(Field protoField, JavaType javaType) { this.protoField = protoField; this.name = protoField.getName(); this.fieldNumber = protoField.getTag(); this.packed = ProtoUtils.isPacked(protoField); int wireType = packed && protoField.isRepeated() ? WireFormat.WIRETYPE_LENGTH_DELIMITED : FieldTypeUtils.convert(protoField.getType()).wireType; this.tag = WireFormat.makeTag(fieldNumber, wireType); this.tagSize = ProtobufOutputEx.computeRawVarint32Size(tag); this.javaType = javaType; this.primitive = javaType.isPrimitive(); }
@Override protected <T> SchemaEx<T> newMessageSchema(Message message, JavaType javaType) { if (ProtoUtils.isWrapProperty(message) && javaType.getRawClass() != PropertyWrapper.class) { Field protoField = message.getField(1); if (javaType.isJavaLangObject()) { javaType = protoField.isRepeated() && protoField.getType().isMessage() && !protoField.isMap() ? ProtoConst.LIST_TYPE : ProtoConst.MAP_TYPE; } javaType = TypeFactory.defaultInstance().constructParametricType(PropertyWrapper.class, javaType); } if (javaType.isJavaLangObject()) { javaType = ProtoConst.MAP_TYPE; } return new MessageReadSchema<>(protoMapper, message, javaType); }
public <T> FieldSchema<T> createSchemaField(Field protoField, PropertyDescriptor propertyDescriptor) { // map is a special repeated if (protoField.isMap()) { return createMapFieldSchema(protoField, propertyDescriptor); } if (protoField.isRepeated()) { return createRepeatedSchema(protoField, propertyDescriptor); } if (isAnyField(protoField)) { return new AnySchema<>(protoMapper, protoField, propertyDescriptor); } if (protoField.getType().isScalar()) { return createScalarField(protoField, propertyDescriptor); } // message if (protoField.getType().isMessage()) { SchemaEx<Object> messageSchema = getOrCreateMessageSchema((Message) protoField.getType(), propertyDescriptor.getJavaType()); if (isWrapProperty((Message) protoField.getType())) { return new PropertyWrapperAsFieldSchema<>(protoField, propertyDescriptor, messageSchema); } return new MessageAsFieldSchema<>(protoField, propertyDescriptor, messageSchema); } if (protoField.isOneofPart()) { throw new IllegalStateException("not IMPL oneof now."); } ProtoUtils.throwNotSupportWrite(protoField, propertyDescriptor.getJavaType().getRawClass()); return null; }
/** * Returns a field getter by index name for proto repeated field. */ public static String repeatedGetByIndexMethodName(Field field) { if (field.isRepeated()) { return GETTER_PREFIX + Formatter.toPascalCase(field.getName()); } throw new IllegalArgumentException(field.toString()); }
/** * Returns a field setter name for proto repeated field. */ public static String getRepeatedFieldSetterName(Field field) { if (field.isRepeated()) { return SETTER_PREFIX + Formatter.toPascalCase(field.getName()); } throw new IllegalArgumentException(field.toString()); }
/** * Returns a field value getter name for proto repeated enum field. */ public static String getRepeatedEnumFieldValueGetterName(Field field) { if (field.isRepeated()) { return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + "ValueList"; } throw new IllegalArgumentException(field.toString()); }
/** * Returns a field converter class name for proto repeated enum field. */ public static String getRepeatedEnumConverterName(Field field) { if (field.isRepeated()) { return "__" + Formatter.toCamelCase(field.getName()) + "Converter"; } throw new IllegalArgumentException(field.toString()); }
/** * Returns a field value setter name for proto repeated enum field. */ public static String getRepeatedEnumValueSetterName(Field field) { if (field.isRepeated()) { return SETTER_PREFIX + Formatter.toPascalCase(field.getName()) + VALUE; } throw new IllegalArgumentException(field.toString()); }
/** * Returns a element count getter name for proto repeated field. */ public static String repeatedGetCountMethodName(Field field) { if (field.isRepeated()) { return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + "Count"; } throw new IllegalArgumentException(field.toString()); }
/** * Returns a java field getter name for proto repeated field. */ public static String getRepeatedFieldGetterName(Field field) { if (field.isRepeated()) { return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + GETTER_REPEATED_SUFFIX; } throw new IllegalArgumentException(field.toString()); }
/** * Returns a field setter name for proto repeated field. */ public static String getRepeatedFieldSetterName(Field field) { if (field.isRepeated()) { return SETTER_PREFIX + Formatter.toPascalCase(field.getName()); } throw new IllegalArgumentException(field.toString()); }
/** * Returns a element count getter name for proto repeated field. */ public static String repeatedGetCountMethodName(Field field) { if (field.isRepeated()) { return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + "Count"; } throw new IllegalArgumentException(field.toString()); }
/** * Returns a field value getter name for proto repeated enum field. */ public static String getRepeatedEnumFieldValueGetterName(Field field) { if (field.isRepeated()) { return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + "ValueList"; } throw new IllegalArgumentException(field.toString()); }
/** * Returns a field value getter by index name for proto repeated enum field. */ public static String javaRepeatedEnumValueGetterByIndexName(Field field) { if (field.isRepeated()) { return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + VALUE; } throw new IllegalArgumentException(field.toString()); }
/** * Returns a java field getter name for proto repeated field. */ public static String getRepeatedFieldGetterName(Field field) { if (field.isRepeated()) { return GETTER_PREFIX + Formatter.toPascalCase(field.getName()) + GETTER_REPEATED_SUFFIX; } throw new IllegalArgumentException(field.toString()); }
/** * Returns a field getter by index name for proto repeated field. */ public static String repeatedGetByIndexMethodName(Field field) { if (field.isRepeated()) { return GETTER_PREFIX + Formatter.toPascalCase(field.getName()); } throw new IllegalArgumentException(field.toString()); }
/** * Returns a field value setter name for proto repeated enum field. */ public static String getRepeatedEnumValueSetterName(Field field) { if (field.isRepeated()) { return SETTER_PREFIX + Formatter.toPascalCase(field.getName()) + VALUE; } throw new IllegalArgumentException(field.toString()); }
private void messageToString(Message message, StringBuilder sb) { appendLine(sb, "message %s {", message.getName()); for (Field field : message.getFields()) { sb.append(" "); fieldToString(field, field.isRepeated(), sb); } appendLine(sb, "}\n"); }