public static void throwNotSupportNullElement(Field protoField) throws IllegalStateException { throw new IllegalStateException( String.format("not support serialize null element, field=%s:%s", ((Type) protoField.getParent()).getCanonicalName(), protoField.getName())); } }
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 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); } } }
@Override public int mergeFrom(InputEx input, T message) throws IOException { int value = input.readInt32(); Enum<?> enumValue = enumMeta.getEnumByValue(value); if (enumValue != null) { setter.set(message, enumValue); return input.readFieldNumber(); } throw new IllegalStateException( String.format("invalid enum value %d for %s, proto field=%s:%s", value, javaType.getRawClass().getName(), ((Type) protoField.getParent()).getCanonicalName(), protoField.getName())); } }
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); } }
public EnumPackedReaders(Field protoField, JavaType javaType) { super(protoField, EnumSchemaUtils.constructEnumArrayClass(javaType)); this.enumMeta = new EnumMeta(protoField, javaType.getContentType()); collectionReader = (input, collection) -> { while (true) { int value = input.readPackedEnum(); Enum<?> enumValue = enumMeta.getEnumByValue(value); if (enumValue == null) { throw new IllegalStateException( String.format("invalid enum value %d for %s, proto field=%s:%s", value, javaType.getRawClass().getName(), ((Type) protoField.getParent()).getCanonicalName(), protoField.getName())); } collection.add(enumValue); int fieldNumber = input.readFieldNumber(); if (fieldNumber != this.fieldNumber) { return fieldNumber; } } }; } }
public EnumNotPackedReaders(Field protoField, JavaType javaType) { super(protoField, EnumSchemaUtils.constructEnumArrayClass(javaType)); this.enumMeta = new EnumMeta(protoField, javaType.getContentType()); collectionReader = (input, collection) -> { while (true) { int value = input.readEnum(); Enum<?> enumValue = enumMeta.getEnumByValue(value); if (enumValue == null) { throw new IllegalStateException( String.format("invalid enum value %d for %s, proto field=%s:%s", value, javaType.getRawClass().getName(), ((Type) protoField.getParent()).getCanonicalName(), protoField.getName())); } collection.add(enumValue); int fieldNumber = input.readFieldNumber(); if (fieldNumber != this.fieldNumber) { return fieldNumber; } } }; } }
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())); }
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); }
@Override public void mergeFrom(Input input, Object message) throws IOException { int ordinal = input.readInt32(); if (javaType.isEnumType()) { Enum<?> enumValue = enumValues.get(ordinal); if (enumValue != null) { setter.set(message, enumValue); return; } throw new IllegalStateException( String.format("invalid enum ordinal value %d for %s, proto field=%s:%s", ordinal, javaType.getRawClass().getName(), ((Type) protoField.getParent()).getCanonicalName(), protoField.getName())); } setter.set(message, ordinal); } }