in foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/repeated/impl/enums/EnumNotPackedWriteSchemas.java [41:106]
public EnumNotPackedWriters(Field protoField, JavaType javaType) {
super(protoField, ReflectUtils.constructArrayType(Enum.class));
this.enumMeta = new EnumMeta(protoField, javaType);
arrayWriter = (output, array) -> {
for (Enum<?> element : array) {
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);
}
};
collectionWriter = (output, collection) -> {
if (collection.isEmpty()) {
return;
}
Object first = collection.iterator().next();
if (first.getClass().isEnum()) {
writeEnumCollection(output, collection);
return;
}
if (first.getClass() == String.class) {
writeStringCollection(output, (Collection<String>) (Object) collection);
return;
}
writeIntCollection(output, (Collection<Number>) (Object) collection);
};
stringArrayWriter = (output, array) -> {
for (String element : array) {
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);
}
};
}