public EnumsPackedWriters()

in foundations/foundation-protobuf/src/main/java/org/apache/servicecomb/foundation/protobuf/internal/schema/serializer/repeated/impl/enums/EnumPackedWriteSchemas.java [41:102]


    public EnumsPackedWriters(Field protoField, JavaType javaType) {
      super(protoField, ReflectUtils.constructArrayType(Enum.class));
      this.enumMeta = new EnumMeta(protoField, javaType);

      arrayWriter = (o, value) -> o.writeObject(tag, tagSize, value, (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.writePackedEnum(enumValue);
        }
      });

      collectionWriter = (o, value) -> o.writeObject(tag, tagSize, value, (output, collection) -> {
        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 = (o, value) -> o.writeObject(tag, tagSize, value, (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.writePackedEnum(enumValue);
        }
      });
    }