public static void throwNotSupportWrite(Field protoField, Class<?> cls) throws IllegalStateException { throw new IllegalStateException( String.format("not support serialize from %s to proto %s, field=%s:%s", cls.getName(), protoField.getTypeName(), ((Type) protoField.getParent()).getCanonicalName(), protoField.getName())); }
public static void throwNotSupportMerge(Field protoField, JavaType javaType) throws IllegalStateException { throw new IllegalStateException( String.format("not support deserialize proto %s as %s, field=%s:%s", protoField.getTypeName(), javaType.toCanonical(), ((Type) protoField.getParent()).getCanonicalName(), protoField.getName())); }
protected final void numberWrite(OutputEx output, Number value) throws IOException { int enumValue = value.intValue(); if (!enumMeta.containsValue(enumValue)) { throw new IllegalStateException( String.format("invalid enum value %d for proto %s, field=%s:%s", enumValue, protoField.getTypeName(), ((Type) protoField.getParent()).getCanonicalName(), protoField.getName())); } output.writeScalarInt32(tag, tagSize, enumValue); }
protected final void stringWrite(OutputEx output, String enumName) throws IOException { Integer enumValue = enumMeta.getValueByName(enumName); if (enumValue == null) { throw new IllegalStateException( String.format("invalid enum name %s for proto %s, field=%s:%s", enumName, protoField.getTypeName(), ((Type) protoField.getParent()).getCanonicalName(), protoField.getName())); } output.writeScalarInt32(tag, tagSize, enumValue); }
private void fieldMapToString(Field field, StringBuilder sb) { Message entryMessage = (Message) field.getType(); Field keyField = entryMessage.getField(1); Field valueField = entryMessage.getField(2); // map<string, string> name = 1; appendLine(sb, "map<%s, %s> %s = %d;", keyField.getTypeName(), valueField.getTypeName(), field.getName(), field.getTag()); } }
private void writeEnumCollection(OutputEx output, Collection<Enum<?>> collection) throws IOException { for (Enum<?> element : collection) { if (element == null) { ProtoUtils.throwNotSupportNullElement(protoField); return; } String name = element.name(); Integer enumValue = enumMeta.getValueByName(name); if (enumValue == null) { throw new IllegalStateException( String.format("invalid enum name %s for proto %s, field=%s:%s", name, protoField.getTypeName(), ((Type) protoField.getParent()).getCanonicalName(), protoField.getName())); } output.writeEnum(tag, tagSize, enumValue); } } }
private void writeEnumCollection(OutputEx output, Collection<Enum<?>> collection) throws IOException { for (Enum<?> element : collection) { if (element == null) { ProtoUtils.throwNotSupportNullElement(protoField); return; } String name = element.name(); Integer enumValue = enumMeta.getValueByName(name); if (enumValue == null) { throw new IllegalStateException( String.format("invalid enum name %s for proto %s, field=%s:%s", name, protoField.getTypeName(), ((Type) protoField.getParent()).getCanonicalName(), protoField.getName())); } output.writePackedEnum(enumValue); } } }
private void writeStringCollection(OutputEx output, Collection<String> collection) throws IOException { for (String element : collection) { if (element == null) { ProtoUtils.throwNotSupportNullElement(protoField); return; } Integer enumValue = enumMeta.getValueByName(element); if (enumValue == null) { throw new IllegalStateException( String.format("invalid enum name %s for proto %s, field=%s:%s", element, protoField.getTypeName(), ((Type) protoField.getParent()).getCanonicalName(), protoField.getName())); } output.writePackedEnum(enumValue); } }
private void writeStringCollection(OutputEx output, Collection<String> collection) throws IOException { for (String element : collection) { if (element == null) { ProtoUtils.throwNotSupportNullElement(protoField); return; } Integer enumValue = enumMeta.getValueByName(element); if (enumValue == null) { throw new IllegalStateException( String.format("invalid enum name %s for proto %s, field=%s:%s", element, protoField.getTypeName(), ((Type) protoField.getParent()).getCanonicalName(), protoField.getName())); } output.writeEnum(tag, tagSize, enumValue); } }
String.format("invalid enum name %s for proto %s, field=%s:%s", name, protoField.getTypeName(), ((Type) protoField.getParent()).getCanonicalName(), protoField.getName())); String.format("invalid enum name %s for proto %s, field=%s:%s", element, protoField.getTypeName(), ((Type) protoField.getParent()).getCanonicalName(), protoField.getName()));
private void fieldToString(Field field, boolean repeated, StringBuilder sb) { if (field.isMap()) { fieldMapToString(field, sb); return; } if (repeated) { fieldRepeatedToString(field, sb); return; } appendLine(sb, "%s %s = %d;", field.getTypeName(), field.getName(), field.getTag()); }
String.format("invalid enum name %s for proto %s, field=%s:%s", name, protoField.getTypeName(), ((Type) protoField.getParent()).getCanonicalName(), protoField.getName())); String.format("invalid enum name %s for proto %s, field=%s:%s", element, protoField.getTypeName(), ((Type) protoField.getParent()).getCanonicalName(), protoField.getName()));
@Override public void mergeFrom(InputEx input, T message) throws IOException { FieldSchema<T> fieldSchema = null; try { for (int n = input.readFieldNumber(); n != 0; ) { fieldSchema = fieldMap.getFieldByNumber(n); if (fieldSchema != null) { n = fieldSchema.mergeFrom(input, message); continue; } input.handleUnknownField(n); n = input.readFieldNumber(); } } catch (Throwable e) { Field protoField = fieldSchema.getProtoField(); LOGGER.error("Failed to mergeFrom, field={}:{}, type={}", protoField.getType().getCanonicalName(), protoField.getName(), protoField.getTypeName(), e.getMessage()); throw e; } }
protected void throwNotSupportValue(Object value) throws IllegalStateException { throw new IllegalStateException( String.format("not support serialize from %s to proto %s, field=%s:%s", value.getClass().getName(), protoField.getTypeName(), ((Type) protoField.getParent()).getCanonicalName(), protoField.getName())); }
private void updateFieldTypes(ProtoContext context, Deque<String> scopeLookupList, FieldContainer fieldContainer) { // check if field type isn't already set fieldContainer.getFields() .stream() .filter(field -> field.getType() == null) // for map fields it is set by parser .forEach(field -> { String typeName = field.getTypeName(); FieldType fieldType = resolveFieldType(field, context, scopeLookupList, typeName); field.setType(fieldType); }); }
protected void serializeFromString(Output output, String enumName) throws IOException { Integer v = enumNameToValueMap.get(enumName); if (v == null) { throw new IllegalStateException( String.format("invalid enum name %s for proto %s, field=%s:%s", enumName, protoField.getTypeName(), ((Type) protoField.getParent()).getCanonicalName(), protoField.getName())); } output.writeInt32(number, v, repeated); }
protected void serializeFromNumber(Output output, int enumValue) throws IOException { if (!enumValueSet.contains(enumValue)) { throw new IllegalStateException( String.format("invalid enum value %d for proto %s, field=%s:%s", enumValue, protoField.getTypeName(), ((Type) protoField.getParent()).getCanonicalName(), protoField.getName())); } output.writeInt32(number, enumValue, repeated); }
protected void logError(FieldSchema fieldSchema, String action, Throwable e) { if (fieldSchema == null) { return; } io.protostuff.compiler.model.Field protoField = fieldSchema.getProtoField(); LOGGER.error("Failed to {}, field={}:{}, type={}", action, protoField.getType().getCanonicalName(), protoField.getName(), protoField.getTypeName(), e.getMessage()); }
private void fieldMapToString(Field field, StringBuilder sb) { Message entryMessage = (Message) field.getType(); Field keyField = entryMessage.getField(1); Field valueField = entryMessage.getField(2); // map<string, string> name = 1; appendLine(sb, "map<%s, %s> %s = %d;", keyField.getTypeName(), valueField.getTypeName(), field.getName(), field.getTag()); } }
private void fieldToString(Field field, boolean repeated, StringBuilder sb) { if (field.isMap()) { fieldMapToString(field, sb); return; } if (repeated) { fieldRepeatedToString(field, sb); return; } appendLine(sb, "%s %s = %d;", field.getTypeName(), field.getName(), field.getTag()); }