Search in sources :

Example 1 with EnumValueDescriptorProto

use of com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto in project aws-glue-schema-registry by awslabs.

the class FileDescriptorUtils method toEnum.

private static EnumElement toEnum(EnumDescriptorProto ed) {
    String name = ed.getName();
    ImmutableList.Builder<EnumConstantElement> constants = ImmutableList.builder();
    for (EnumValueDescriptorProto ev : ed.getValueList()) {
        ImmutableList.Builder<OptionElement> options = ImmutableList.builder();
        constants.add(new EnumConstantElement(DEFAULT_LOCATION, ev.getName(), ev.getNumber(), "", options.build()));
    }
    ImmutableList.Builder<OptionElement> options = ImmutableList.builder();
    if (ed.getOptions().hasAllowAlias()) {
        OptionElement option = new OptionElement(ALLOW_ALIAS_OPTION, booleanKind, ed.getOptions().getAllowAlias(), false);
        options.add(option);
    }
    return new EnumElement(DEFAULT_LOCATION, name, "", options.build(), constants.build());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) OptionElement(com.squareup.wire.schema.internal.parser.OptionElement) EnumValueDescriptorProto(com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto) EnumConstantElement(com.squareup.wire.schema.internal.parser.EnumConstantElement) EnumElement(com.squareup.wire.schema.internal.parser.EnumElement)

Example 2 with EnumValueDescriptorProto

use of com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto in project schema-registry by confluentinc.

the class ProtobufSchema method toEnum.

private static EnumElement toEnum(EnumDescriptorProto ed) {
    String name = ed.getName();
    log.trace("*** enum name: {}", name);
    ImmutableList.Builder<EnumConstantElement> constants = ImmutableList.builder();
    for (EnumValueDescriptorProto ev : ed.getValueList()) {
        ImmutableList.Builder<OptionElement> options = ImmutableList.builder();
        if (ev.getOptions().hasDeprecated()) {
            OptionElement option = new OptionElement(DEPRECATED, Kind.BOOLEAN, ev.getOptions().getDeprecated(), false);
            options.add(option);
        }
        if (ev.getOptions().hasExtension(MetaProto.enumValueMeta)) {
            Meta meta = ev.getOptions().getExtension(MetaProto.enumValueMeta);
            OptionElement option = toOption(CONFLUENT_ENUM_VALUE_META, meta);
            if (option != null) {
                options.add(option);
            }
        }
        constants.add(new EnumConstantElement(DEFAULT_LOCATION, ev.getName(), ev.getNumber(), "", options.build()));
    }
    ImmutableList.Builder<ReservedElement> reserved = ImmutableList.builder();
    for (EnumReservedRange range : ed.getReservedRangeList()) {
        ReservedElement reservedElem = toReserved(range);
        reserved.add(reservedElem);
    }
    for (String reservedName : ed.getReservedNameList()) {
        ReservedElement reservedElem = new ReservedElement(DEFAULT_LOCATION, "", Collections.singletonList(reservedName));
        reserved.add(reservedElem);
    }
    ImmutableList.Builder<OptionElement> options = ImmutableList.builder();
    if (ed.getOptions().hasAllowAlias()) {
        OptionElement option = new OptionElement(ALLOW_ALIAS, Kind.BOOLEAN, ed.getOptions().getAllowAlias(), false);
        options.add(option);
    }
    if (ed.getOptions().hasDeprecated()) {
        OptionElement option = new OptionElement(DEPRECATED, Kind.BOOLEAN, ed.getOptions().getDeprecated(), false);
        options.add(option);
    }
    if (ed.getOptions().hasExtension(MetaProto.enumMeta)) {
        Meta meta = ed.getOptions().getExtension(MetaProto.enumMeta);
        OptionElement option = toOption(CONFLUENT_ENUM_META, meta);
        if (option != null) {
            options.add(option);
        }
    }
    return new EnumElement(DEFAULT_LOCATION, name, "", options.build(), constants.build(), reserved.build());
}
Also used : Meta(io.confluent.protobuf.MetaProto.Meta) EnumReservedRange(com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRange) ImmutableList(com.google.common.collect.ImmutableList) OptionElement(com.squareup.wire.schema.internal.parser.OptionElement) ReservedElement(com.squareup.wire.schema.internal.parser.ReservedElement) EnumValueDescriptorProto(com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto) EnumConstantElement(com.squareup.wire.schema.internal.parser.EnumConstantElement) EnumElement(com.squareup.wire.schema.internal.parser.EnumElement)

Example 3 with EnumValueDescriptorProto

use of com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto in project apicurio-registry by Apicurio.

the class FileDescriptorUtils method toEnum.

private static EnumElement toEnum(EnumDescriptorProto ed) {
    String name = ed.getName();
    ImmutableList.Builder<EnumConstantElement> constants = ImmutableList.builder();
    for (EnumValueDescriptorProto ev : ed.getValueList()) {
        ImmutableList.Builder<OptionElement> options = ImmutableList.builder();
        constants.add(new EnumConstantElement(DEFAULT_LOCATION, ev.getName(), ev.getNumber(), "", options.build()));
    }
    ImmutableList.Builder<OptionElement> options = ImmutableList.builder();
    if (ed.getOptions().hasAllowAlias()) {
        OptionElement option = new OptionElement(ALLOW_ALIAS_OPTION, booleanKind, ed.getOptions().getAllowAlias(), false);
        options.add(option);
    }
    return new EnumElement(DEFAULT_LOCATION, name, "", options.build(), constants.build());
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) OptionElement(com.squareup.wire.schema.internal.parser.OptionElement) EnumValueDescriptorProto(com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto) EnumConstantElement(com.squareup.wire.schema.internal.parser.EnumConstantElement) EnumElement(com.squareup.wire.schema.internal.parser.EnumElement)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)3 EnumValueDescriptorProto (com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto)3 EnumConstantElement (com.squareup.wire.schema.internal.parser.EnumConstantElement)3 EnumElement (com.squareup.wire.schema.internal.parser.EnumElement)3 OptionElement (com.squareup.wire.schema.internal.parser.OptionElement)3 EnumReservedRange (com.google.protobuf.DescriptorProtos.EnumDescriptorProto.EnumReservedRange)1 ReservedElement (com.squareup.wire.schema.internal.parser.ReservedElement)1 Meta (io.confluent.protobuf.MetaProto.Meta)1