Java Code Examples for io.protostuff.compiler.model.Field#getTag()

The following examples show how to use io.protostuff.compiler.model.Field#getTag() . 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: AbstractReaders.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
public AbstractReaders(Field protoField, Class<T[]> arrayClass) {
  this.protoField = protoField;
  this.fieldNumber = protoField.getTag();

  if (arrayClass == null) {
    arrayClass = getFieldArgument(this.getClass(), "arrayClass");
  }
  this.arrayClass = arrayClass;
}
 
Example 2
Source File: FieldSchema.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 3
Source File: ExtensionRegistratorPostProcessor.java    From protostuff-compiler with Apache License 2.0 5 votes vote down vote up
private void checkRanges(Field field, List<Range> ranges) {
    int tag = field.getTag();
    boolean inRange = false;
    for (Range range : ranges) {
        int from = range.getFrom();
        int to = range.getTo();
        if (tag >= from && tag <= to) {
            inRange = true;
        }
    }
    if (!inRange) {
        String format = "Extension field '%s' tag=%d is out of allowed range";
        throw new ParserException(field, format, field.getName(), tag);
    }
}
 
Example 4
Source File: UserTypeValidationPostProcessor.java    From protostuff-compiler with Apache License 2.0 5 votes vote down vote up
private void checkReservedFieldTags(Message message, List<Field> fields) {
    List<Range> ranges = message.getReservedFieldRanges();
    for (Field field : fields) {
        int tag = field.getTag();
        for (Range range : ranges) {
            if (range.contains(tag)) {
                throw new ParserException(field, "Reserved field tag: %d", tag);
            }
        }
    }
}
 
Example 5
Source File: UserTypeValidationPostProcessor.java    From protostuff-compiler with Apache License 2.0 5 votes vote down vote up
private void checkInvalidFieldTags(List<Field> fields) {
    for (Field field : fields) {
        int tag = field.getTag();
        if (!isValidTagValue(tag)) {
            throw new ParserException(field, "Invalid tag: %d, allowed range is [%d, %d) and (%d, %d]",
                    tag, MIN_TAG, SYS_RESERVED_START, SYS_RESERVED_END, MAX_TAG);
        }
    }
}
 
Example 6
Source File: UserTypeValidationPostProcessor.java    From protostuff-compiler with Apache License 2.0 5 votes vote down vote up
private void checkDuplicateFieldTags(List<Field> fields) {
    Map<Integer, Field> fieldByTag = new HashMap<>();
    for (Field field : fields) {
        int tag = field.getTag();
        if (fieldByTag.containsKey(tag)) {
            throw new ParserException(field, "Duplicate field tag: %d", tag);
        }
        fieldByTag.put(tag, field);
    }
}