Search in sources :

Example 16 with EnumElement

use of com.squareup.wire.schema.internal.parser.EnumElement in project apicurio-registry by Apicurio.

the class FileDescriptorUtils method toDynamicMessage.

private static MessageDefinition toDynamicMessage(MessageElement messageElem) {
    MessageDefinition.Builder message = MessageDefinition.newBuilder(messageElem.getName());
    for (TypeElement type : messageElem.getNestedTypes()) {
        if (type instanceof MessageElement) {
            message.addMessageDefinition(toDynamicMessage((MessageElement) type));
        } else if (type instanceof EnumElement) {
            message.addEnumDefinition(toDynamicEnum((EnumElement) type));
        }
    }
    Set<String> added = new HashSet<>();
    for (OneOfElement oneof : messageElem.getOneOfs()) {
        MessageDefinition.OneofBuilder oneofBuilder = message.addOneof(oneof.getName());
        for (FieldElement field : oneof.getFields()) {
            String defaultVal = field.getDefaultValue();
            String jsonName = findOption("json_name", field.getOptions()).map(o -> o.getValue().toString()).orElse(null);
            oneofBuilder.addField(field.getType(), field.getName(), field.getTag(), defaultVal, jsonName);
            added.add(field.getName());
        }
    }
    // Process fields after messages so that any newly created map entry messages are at the end
    for (FieldElement field : messageElem.getFields()) {
        if (added.contains(field.getName())) {
            continue;
        }
        Field.Label fieldLabel = field.getLabel();
        String label = fieldLabel != null ? fieldLabel.toString().toLowerCase() : null;
        String fieldType = field.getType();
        String defaultVal = field.getDefaultValue();
        String jsonName = field.getJsonName();
        Boolean isPacked = findOption("packed", field.getOptions()).map(o -> Boolean.valueOf(o.getValue().toString())).orElse(null);
        ProtoType protoType = ProtoType.get(fieldType);
        ProtoType keyType = protoType.getKeyType();
        ProtoType valueType = protoType.getValueType();
        // Map fields are only permitted in messages
        if (protoType.isMap() && keyType != null && valueType != null) {
            label = "repeated";
            fieldType = toMapEntry(field.getName());
            MessageDefinition.Builder mapMessage = MessageDefinition.newBuilder(fieldType);
            mapMessage.setMapEntry(true);
            mapMessage.addField(null, keyType.getSimpleName(), KEY_FIELD, 1, null);
            mapMessage.addField(null, valueType.getSimpleName(), VALUE_FIELD, 2, null);
            message.addMessageDefinition(mapMessage.build());
        }
        message.addField(label, fieldType, field.getName(), field.getTag(), defaultVal, jsonName, isPacked);
    }
    for (ReservedElement reserved : messageElem.getReserveds()) {
        for (Object elem : reserved.getValues()) {
            if (elem instanceof String) {
                message.addReservedName((String) elem);
            } else if (elem instanceof Integer) {
                int tag = (Integer) elem;
                message.addReservedRange(tag, tag);
            } else if (elem instanceof IntRange) {
                IntRange range = (IntRange) elem;
                message.addReservedRange(range.getStart(), range.getEndInclusive());
            } else {
                throw new IllegalStateException("Unsupported reserved type: " + elem.getClass().getName());
            }
        }
    }
    Boolean isMapEntry = findOption("map_entry", messageElem.getOptions()).map(o -> Boolean.valueOf(o.getValue().toString())).orElse(null);
    if (isMapEntry != null) {
        message.setMapEntry(isMapEntry);
    }
    return message.build();
}
Also used : QuaternionProto(com.google.type.QuaternionProto) Decimals(additionalTypes.Decimals) com.google.protobuf(com.google.protobuf) ServiceDescriptorProto(com.google.protobuf.DescriptorProtos.ServiceDescriptorProto) ReservedElement(com.squareup.wire.schema.internal.parser.ReservedElement) DescriptorValidationException(com.google.protobuf.Descriptors.DescriptorValidationException) Service(com.squareup.wire.schema.Service) Type(com.squareup.wire.schema.Type) Map(java.util.Map) MethodDescriptorProto(com.google.protobuf.DescriptorProtos.MethodDescriptorProto) OneofDescriptorProto(com.google.protobuf.DescriptorProtos.OneofDescriptorProto) PhoneNumberProto(com.google.type.PhoneNumberProto) ExprProto(com.google.type.ExprProto) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) DayOfWeek(com.google.type.DayOfWeek) IntRange(kotlin.ranges.IntRange) ExtensionsElement(com.squareup.wire.schema.internal.parser.ExtensionsElement) Predicate(java.util.function.Predicate) MonthProto(com.google.type.MonthProto) Set(java.util.Set) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) ProtoType(com.squareup.wire.schema.ProtoType) Collectors(java.util.stream.Collectors) EnumConstant(com.squareup.wire.schema.EnumConstant) IntervalProto(com.google.type.IntervalProto) Objects(java.util.Objects) List(java.util.List) EnumConstantElement(com.squareup.wire.schema.internal.parser.EnumConstantElement) FieldElement(com.squareup.wire.schema.internal.parser.FieldElement) PostalAddressProto(com.google.type.PostalAddressProto) EnumDescriptorProto(com.google.protobuf.DescriptorProtos.EnumDescriptorProto) FileDescriptorProto(com.google.protobuf.DescriptorProtos.FileDescriptorProto) TypeElement(com.squareup.wire.schema.internal.parser.TypeElement) Optional(java.util.Optional) OneOfElement(com.squareup.wire.schema.internal.parser.OneOfElement) EnumValueDescriptorProto(com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto) ColorProto(com.google.type.ColorProto) FileOptions(com.google.protobuf.DescriptorProtos.FileOptions) TimeOfDayProto(com.google.type.TimeOfDayProto) Schema(com.squareup.wire.schema.Schema) OneOf(com.squareup.wire.schema.OneOf) OptionElement(com.squareup.wire.schema.internal.parser.OptionElement) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Rpc(com.squareup.wire.schema.Rpc) Location(com.squareup.wire.schema.Location) ImmutableList(com.google.common.collect.ImmutableList) Syntax(com.squareup.wire.Syntax) MoneyProto(com.google.type.MoneyProto) RpcElement(com.squareup.wire.schema.internal.parser.RpcElement) MessageType(com.squareup.wire.schema.MessageType) LinkedHashSet(java.util.LinkedHashSet) LOWER_UNDERSCORE(com.google.common.base.CaseFormat.LOWER_UNDERSCORE) ProtoFileElement(com.squareup.wire.schema.internal.parser.ProtoFileElement) FieldDescriptorProto(com.google.protobuf.DescriptorProtos.FieldDescriptorProto) DateProto(com.google.type.DateProto) ProtoFile(com.squareup.wire.schema.ProtoFile) LatLng(com.google.type.LatLng) UPPER_CAMEL(com.google.common.base.CaseFormat.UPPER_CAMEL) CalendarPeriodProto(com.google.type.CalendarPeriodProto) EnumElement(com.squareup.wire.schema.internal.parser.EnumElement) TreeMap(java.util.TreeMap) Field(com.squareup.wire.schema.Field) ServiceElement(com.squareup.wire.schema.internal.parser.ServiceElement) Options(com.squareup.wire.schema.Options) LocalizedTextProto(com.google.type.LocalizedTextProto) EnumType(com.squareup.wire.schema.EnumType) ProtobufSchemaMetadata(metadata.ProtobufSchemaMetadata) Comparator(java.util.Comparator) DescriptorProto(com.google.protobuf.DescriptorProtos.DescriptorProto) Collections(java.util.Collections) MethodOptions(com.google.protobuf.DescriptorProtos.MethodOptions) FractionProto(com.google.type.FractionProto) MessageElement(com.squareup.wire.schema.internal.parser.MessageElement) TypeElement(com.squareup.wire.schema.internal.parser.TypeElement) FieldElement(com.squareup.wire.schema.internal.parser.FieldElement) IntRange(kotlin.ranges.IntRange) ReservedElement(com.squareup.wire.schema.internal.parser.ReservedElement) MessageElement(com.squareup.wire.schema.internal.parser.MessageElement) EnumElement(com.squareup.wire.schema.internal.parser.EnumElement) ProtoType(com.squareup.wire.schema.ProtoType) Field(com.squareup.wire.schema.Field) OneOfElement(com.squareup.wire.schema.internal.parser.OneOfElement) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 17 with EnumElement

use of com.squareup.wire.schema.internal.parser.EnumElement in project apicurio-registry by Apicurio.

the class FileDescriptorUtils method toMessage.

private static MessageElement toMessage(FileDescriptorProto file, DescriptorProto descriptor) {
    String name = descriptor.getName();
    ImmutableList.Builder<FieldElement> fields = ImmutableList.builder();
    ImmutableList.Builder<TypeElement> nested = ImmutableList.builder();
    ImmutableList.Builder<ReservedElement> reserved = ImmutableList.builder();
    ImmutableList.Builder<ExtensionsElement> extensions = ImmutableList.builder();
    LinkedHashMap<String, ImmutableList.Builder<FieldElement>> oneofsMap = new LinkedHashMap<>();
    for (OneofDescriptorProto od : descriptor.getOneofDeclList()) {
        oneofsMap.put(od.getName(), ImmutableList.builder());
    }
    List<Map.Entry<String, ImmutableList.Builder<FieldElement>>> oneofs = new ArrayList<>(oneofsMap.entrySet());
    List<FieldElement> proto3OptionalFields = new ArrayList<>();
    for (FieldDescriptorProto fd : descriptor.getFieldList()) {
        if (fd.hasProto3Optional()) {
            proto3OptionalFields.add(toField(file, fd, false));
            continue;
        }
        if (fd.hasOneofIndex()) {
            FieldElement field = toField(file, fd, true);
            oneofs.get(fd.getOneofIndex()).getValue().add(field);
        } else {
            FieldElement field = toField(file, fd, false);
            fields.add(field);
        }
    }
    fields.addAll(proto3OptionalFields);
    for (DescriptorProto nestedDesc : descriptor.getNestedTypeList()) {
        MessageElement nestedMessage = toMessage(file, nestedDesc);
        nested.add(nestedMessage);
    }
    for (EnumDescriptorProto nestedDesc : descriptor.getEnumTypeList()) {
        EnumElement nestedEnum = toEnum(nestedDesc);
        nested.add(nestedEnum);
    }
    for (String reservedName : descriptor.getReservedNameList()) {
        ReservedElement reservedElem = new ReservedElement(DEFAULT_LOCATION, "", Collections.singletonList(reservedName));
        reserved.add(reservedElem);
    }
    for (DescriptorProto.ReservedRange reservedRange : descriptor.getReservedRangeList()) {
        List<IntRange> values = new ArrayList<>();
        int start = reservedRange.getStart();
        int end = reservedRange.getEnd() - 1;
        values.add(new IntRange(start, end));
        ReservedElement reservedElem = new ReservedElement(DEFAULT_LOCATION, "", values);
        reserved.add(reservedElem);
    }
    for (DescriptorProto.ExtensionRange extensionRange : descriptor.getExtensionRangeList()) {
        List<IntRange> values = new ArrayList<>();
        int start = extensionRange.getStart();
        int end = extensionRange.getEnd() - 1;
        values.add(new IntRange(start, end));
        ExtensionsElement extensionsElement = new ExtensionsElement(DEFAULT_LOCATION, "", values);
        extensions.add(extensionsElement);
    }
    ImmutableList.Builder<OptionElement> options = ImmutableList.builder();
    if (descriptor.getOptions().hasMapEntry()) {
        OptionElement option = new OptionElement(MAP_ENTRY_OPTION, booleanKind, descriptor.getOptions().getMapEntry(), false);
        options.add(option);
    }
    if (descriptor.getOptions().hasNoStandardDescriptorAccessor()) {
        OptionElement option = new OptionElement(NO_STANDARD_DESCRIPTOR_OPTION, booleanKind, descriptor.getOptions().getNoStandardDescriptorAccessor(), false);
        options.add(option);
    }
    return new MessageElement(DEFAULT_LOCATION, name, "", nested.build(), options.build(), reserved.build(), fields.build(), oneofs.stream().filter(e -> e.getValue().build().size() != 0).map(e -> toOneof(e.getKey(), e.getValue())).collect(Collectors.toList()), extensions.build(), Collections.emptyList());
}
Also used : QuaternionProto(com.google.type.QuaternionProto) Decimals(additionalTypes.Decimals) com.google.protobuf(com.google.protobuf) ServiceDescriptorProto(com.google.protobuf.DescriptorProtos.ServiceDescriptorProto) ReservedElement(com.squareup.wire.schema.internal.parser.ReservedElement) DescriptorValidationException(com.google.protobuf.Descriptors.DescriptorValidationException) Service(com.squareup.wire.schema.Service) Type(com.squareup.wire.schema.Type) Map(java.util.Map) MethodDescriptorProto(com.google.protobuf.DescriptorProtos.MethodDescriptorProto) OneofDescriptorProto(com.google.protobuf.DescriptorProtos.OneofDescriptorProto) PhoneNumberProto(com.google.type.PhoneNumberProto) ExprProto(com.google.type.ExprProto) FileDescriptor(com.google.protobuf.Descriptors.FileDescriptor) DayOfWeek(com.google.type.DayOfWeek) IntRange(kotlin.ranges.IntRange) ExtensionsElement(com.squareup.wire.schema.internal.parser.ExtensionsElement) Predicate(java.util.function.Predicate) MonthProto(com.google.type.MonthProto) Set(java.util.Set) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) ProtoType(com.squareup.wire.schema.ProtoType) Collectors(java.util.stream.Collectors) EnumConstant(com.squareup.wire.schema.EnumConstant) IntervalProto(com.google.type.IntervalProto) Objects(java.util.Objects) List(java.util.List) EnumConstantElement(com.squareup.wire.schema.internal.parser.EnumConstantElement) FieldElement(com.squareup.wire.schema.internal.parser.FieldElement) PostalAddressProto(com.google.type.PostalAddressProto) EnumDescriptorProto(com.google.protobuf.DescriptorProtos.EnumDescriptorProto) FileDescriptorProto(com.google.protobuf.DescriptorProtos.FileDescriptorProto) TypeElement(com.squareup.wire.schema.internal.parser.TypeElement) Optional(java.util.Optional) OneOfElement(com.squareup.wire.schema.internal.parser.OneOfElement) EnumValueDescriptorProto(com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto) ColorProto(com.google.type.ColorProto) FileOptions(com.google.protobuf.DescriptorProtos.FileOptions) TimeOfDayProto(com.google.type.TimeOfDayProto) Schema(com.squareup.wire.schema.Schema) OneOf(com.squareup.wire.schema.OneOf) OptionElement(com.squareup.wire.schema.internal.parser.OptionElement) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Rpc(com.squareup.wire.schema.Rpc) Location(com.squareup.wire.schema.Location) ImmutableList(com.google.common.collect.ImmutableList) Syntax(com.squareup.wire.Syntax) MoneyProto(com.google.type.MoneyProto) RpcElement(com.squareup.wire.schema.internal.parser.RpcElement) MessageType(com.squareup.wire.schema.MessageType) LinkedHashSet(java.util.LinkedHashSet) LOWER_UNDERSCORE(com.google.common.base.CaseFormat.LOWER_UNDERSCORE) ProtoFileElement(com.squareup.wire.schema.internal.parser.ProtoFileElement) FieldDescriptorProto(com.google.protobuf.DescriptorProtos.FieldDescriptorProto) DateProto(com.google.type.DateProto) ProtoFile(com.squareup.wire.schema.ProtoFile) LatLng(com.google.type.LatLng) UPPER_CAMEL(com.google.common.base.CaseFormat.UPPER_CAMEL) CalendarPeriodProto(com.google.type.CalendarPeriodProto) EnumElement(com.squareup.wire.schema.internal.parser.EnumElement) TreeMap(java.util.TreeMap) Field(com.squareup.wire.schema.Field) ServiceElement(com.squareup.wire.schema.internal.parser.ServiceElement) Options(com.squareup.wire.schema.Options) LocalizedTextProto(com.google.type.LocalizedTextProto) EnumType(com.squareup.wire.schema.EnumType) ProtobufSchemaMetadata(metadata.ProtobufSchemaMetadata) Comparator(java.util.Comparator) DescriptorProto(com.google.protobuf.DescriptorProtos.DescriptorProto) Collections(java.util.Collections) MethodOptions(com.google.protobuf.DescriptorProtos.MethodOptions) FractionProto(com.google.type.FractionProto) MessageElement(com.squareup.wire.schema.internal.parser.MessageElement) EnumDescriptorProto(com.google.protobuf.DescriptorProtos.EnumDescriptorProto) ImmutableList(com.google.common.collect.ImmutableList) FieldElement(com.squareup.wire.schema.internal.parser.FieldElement) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ExtensionsElement(com.squareup.wire.schema.internal.parser.ExtensionsElement) OptionElement(com.squareup.wire.schema.internal.parser.OptionElement) ServiceDescriptorProto(com.google.protobuf.DescriptorProtos.ServiceDescriptorProto) MethodDescriptorProto(com.google.protobuf.DescriptorProtos.MethodDescriptorProto) OneofDescriptorProto(com.google.protobuf.DescriptorProtos.OneofDescriptorProto) EnumDescriptorProto(com.google.protobuf.DescriptorProtos.EnumDescriptorProto) FileDescriptorProto(com.google.protobuf.DescriptorProtos.FileDescriptorProto) EnumValueDescriptorProto(com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto) FieldDescriptorProto(com.google.protobuf.DescriptorProtos.FieldDescriptorProto) DescriptorProto(com.google.protobuf.DescriptorProtos.DescriptorProto) TypeElement(com.squareup.wire.schema.internal.parser.TypeElement) OneofDescriptorProto(com.google.protobuf.DescriptorProtos.OneofDescriptorProto) IntRange(kotlin.ranges.IntRange) ReservedElement(com.squareup.wire.schema.internal.parser.ReservedElement) FieldDescriptorProto(com.google.protobuf.DescriptorProtos.FieldDescriptorProto) MessageElement(com.squareup.wire.schema.internal.parser.MessageElement) EnumElement(com.squareup.wire.schema.internal.parser.EnumElement)

Example 18 with EnumElement

use of com.squareup.wire.schema.internal.parser.EnumElement 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)

Example 19 with EnumElement

use of com.squareup.wire.schema.internal.parser.EnumElement in project thingsboard by thingsboard.

the class ProtoTransportPayloadConfiguration method getMessageDefinitions.

private List<MessageDefinition> getMessageDefinitions(List<MessageElement> messageElementsList) {
    if (!messageElementsList.isEmpty()) {
        List<MessageDefinition> messageDefinitions = new ArrayList<>();
        messageElementsList.forEach(messageElement -> {
            MessageDefinition.Builder messageDefinitionBuilder = MessageDefinition.newBuilder(messageElement.getName());
            List<TypeElement> nestedTypes = messageElement.getNestedTypes();
            if (!nestedTypes.isEmpty()) {
                List<EnumElement> nestedEnumTypes = getEnumElements(nestedTypes);
                if (!nestedEnumTypes.isEmpty()) {
                    nestedEnumTypes.forEach(enumElement -> {
                        EnumDefinition nestedEnumDefinition = getEnumDefinition(enumElement);
                        messageDefinitionBuilder.addEnumDefinition(nestedEnumDefinition);
                    });
                }
                List<MessageElement> nestedMessageTypes = getMessageTypes(nestedTypes);
                List<MessageDefinition> nestedMessageDefinitions = getMessageDefinitions(nestedMessageTypes);
                nestedMessageDefinitions.forEach(messageDefinitionBuilder::addMessageDefinition);
            }
            List<FieldElement> messageElementFields = messageElement.getFields();
            List<OneOfElement> oneOfs = messageElement.getOneOfs();
            if (!oneOfs.isEmpty()) {
                for (OneOfElement oneOfelement : oneOfs) {
                    MessageDefinition.OneofBuilder oneofBuilder = messageDefinitionBuilder.addOneof(oneOfelement.getName());
                    addMessageFieldsToTheOneOfDefinition(oneOfelement.getFields(), oneofBuilder);
                }
            }
            if (!messageElementFields.isEmpty()) {
                addMessageFieldsToTheMessageDefinition(messageElementFields, messageDefinitionBuilder);
            }
            messageDefinitions.add(messageDefinitionBuilder.build());
        });
        return messageDefinitions;
    } else {
        return Collections.emptyList();
    }
}
Also used : TypeElement(com.squareup.wire.schema.internal.parser.TypeElement) ArrayList(java.util.ArrayList) FieldElement(com.squareup.wire.schema.internal.parser.FieldElement) MessageElement(com.squareup.wire.schema.internal.parser.MessageElement) EnumDefinition(com.github.os72.protobuf.dynamic.EnumDefinition) EnumElement(com.squareup.wire.schema.internal.parser.EnumElement) MessageDefinition(com.github.os72.protobuf.dynamic.MessageDefinition) OneOfElement(com.squareup.wire.schema.internal.parser.OneOfElement)

Example 20 with EnumElement

use of com.squareup.wire.schema.internal.parser.EnumElement in project schema-registry by confluentinc.

the class ProtobufSchema method toDynamicSchema.

private static DynamicSchema toDynamicSchema(String name, ProtoFileElement rootElem, Map<String, ProtoFileElement> dependencies) {
    if (log.isTraceEnabled()) {
        log.trace("*** toDynamicSchema: {}", ProtobufSchemaUtils.toString(rootElem));
    }
    DynamicSchema.Builder schema = DynamicSchema.newBuilder();
    try {
        Syntax syntax = rootElem.getSyntax();
        if (syntax != null) {
            schema.setSyntax(syntax.toString());
        }
        if (rootElem.getPackageName() != null) {
            schema.setPackage(rootElem.getPackageName());
        }
        for (TypeElement typeElem : rootElem.getTypes()) {
            if (typeElem instanceof MessageElement) {
                MessageDefinition message = toDynamicMessage(syntax, (MessageElement) typeElem);
                schema.addMessageDefinition(message);
            } else if (typeElem instanceof EnumElement) {
                EnumDefinition enumer = toDynamicEnum((EnumElement) typeElem);
                schema.addEnumDefinition(enumer);
            }
        }
        for (ServiceElement serviceElement : rootElem.getServices()) {
            ServiceDefinition service = toDynamicService(serviceElement);
            schema.addServiceDefinition(service);
        }
        for (String ref : rootElem.getImports()) {
            ProtoFileElement dep = dependencies.get(ref);
            if (dep != null) {
                schema.addDependency(ref);
                schema.addSchema(toDynamicSchema(ref, dep, dependencies));
            }
        }
        for (String ref : rootElem.getPublicImports()) {
            ProtoFileElement dep = dependencies.get(ref);
            if (dep != null) {
                schema.addPublicDependency(ref);
                schema.addSchema(toDynamicSchema(ref, dep, dependencies));
            }
        }
        Map<String, OptionElement> options = mergeOptions(rootElem.getOptions());
        OptionElement javaPackageName = options.get(JAVA_PACKAGE);
        if (javaPackageName != null) {
            schema.setJavaPackage(javaPackageName.getValue().toString());
        }
        OptionElement javaOuterClassname = options.get(JAVA_OUTER_CLASSNAME);
        if (javaOuterClassname != null) {
            schema.setJavaOuterClassname(javaOuterClassname.getValue().toString());
        }
        OptionElement javaMultipleFiles = options.get(JAVA_MULTIPLE_FILES);
        if (javaMultipleFiles != null) {
            schema.setJavaMultipleFiles(Boolean.parseBoolean(javaMultipleFiles.getValue().toString()));
        }
        OptionElement javaStringCheckUtf8 = options.get(JAVA_STRING_CHECK_UTF8);
        if (javaStringCheckUtf8 != null) {
            schema.setJavaStringCheckUtf8(Boolean.parseBoolean(javaStringCheckUtf8.getValue().toString()));
        }
        OptionElement optimizeFor = options.get(OPTIMIZE_FOR);
        if (optimizeFor != null) {
            schema.setOptimizeFor(OptimizeMode.valueOf(optimizeFor.getValue().toString()));
        }
        OptionElement goPackage = options.get(GO_PACKAGE);
        if (goPackage != null) {
            schema.setGoPackage(goPackage.getValue().toString());
        }
        OptionElement ccGenericServices = options.get(CC_GENERIC_SERVICES);
        if (ccGenericServices != null) {
            schema.setCcGenericServices(Boolean.parseBoolean(ccGenericServices.getValue().toString()));
        }
        OptionElement javaGenericServices = options.get(JAVA_GENERIC_SERVICES);
        if (javaGenericServices != null) {
            schema.setJavaGenericServices(Boolean.parseBoolean(javaGenericServices.getValue().toString()));
        }
        OptionElement pyGenericServices = options.get(PY_GENERIC_SERVICES);
        if (pyGenericServices != null) {
            schema.setPyGenericServices(Boolean.parseBoolean(pyGenericServices.getValue().toString()));
        }
        OptionElement phpGenericServices = options.get(PHP_GENERIC_SERVICES);
        if (phpGenericServices != null) {
            schema.setPhpGenericServices(Boolean.parseBoolean(phpGenericServices.getValue().toString()));
        }
        OptionElement isDeprecated = options.get(DEPRECATED);
        if (isDeprecated != null) {
            schema.setDeprecated(Boolean.parseBoolean(isDeprecated.getValue().toString()));
        }
        OptionElement ccEnableArenas = options.get(CC_ENABLE_ARENAS);
        if (ccEnableArenas != null) {
            schema.setCcEnableArenas(Boolean.parseBoolean(ccEnableArenas.getValue().toString()));
        }
        OptionElement objcClassPrefix = options.get(OBJC_CLASS_PREFIX);
        if (objcClassPrefix != null) {
            schema.setObjcClassPrefix(objcClassPrefix.getValue().toString());
        }
        OptionElement csharpNamespace = options.get(CSHARP_NAMESPACE);
        if (csharpNamespace != null) {
            schema.setCsharpNamespace(csharpNamespace.getValue().toString());
        }
        OptionElement swiftPrefix = options.get(SWIFT_PREFIX);
        if (swiftPrefix != null) {
            schema.setSwiftPrefix(swiftPrefix.getValue().toString());
        }
        OptionElement phpClassPrefix = options.get(PHP_CLASS_PREFIX);
        if (phpClassPrefix != null) {
            schema.setPhpClassPrefix(phpClassPrefix.getValue().toString());
        }
        OptionElement phpNamespace = options.get(PHP_NAMESPACE);
        if (phpNamespace != null) {
            schema.setPhpNamespace(phpNamespace.getValue().toString());
        }
        OptionElement phpMetadataNamespace = options.get(PHP_METADATA_NAMESPACE);
        if (phpMetadataNamespace != null) {
            schema.setPhpMetadataNamespace(phpMetadataNamespace.getValue().toString());
        }
        OptionElement rubyPackage = options.get(RUBY_PACKAGE);
        if (rubyPackage != null) {
            schema.setRubyPackage(rubyPackage.getValue().toString());
        }
        Optional<OptionElement> meta = findOption(CONFLUENT_FILE_META, options);
        String doc = findDoc(meta);
        Map<String, String> params = findParams(meta);
        schema.setMeta(doc, params);
        schema.setName(name);
        return schema.build();
    } catch (Descriptors.DescriptorValidationException e) {
        throw new IllegalStateException(e);
    }
}
Also used : TypeElement(com.squareup.wire.schema.internal.parser.TypeElement) MessageElement(com.squareup.wire.schema.internal.parser.MessageElement) DynamicSchema(io.confluent.kafka.schemaregistry.protobuf.dynamic.DynamicSchema) EnumDefinition(io.confluent.kafka.schemaregistry.protobuf.dynamic.EnumDefinition) ProtoFileElement(com.squareup.wire.schema.internal.parser.ProtoFileElement) EnumElement(com.squareup.wire.schema.internal.parser.EnumElement) ServiceElement(com.squareup.wire.schema.internal.parser.ServiceElement) MessageDefinition(io.confluent.kafka.schemaregistry.protobuf.dynamic.MessageDefinition) OptionElement(com.squareup.wire.schema.internal.parser.OptionElement) Descriptors(com.google.protobuf.Descriptors) Syntax(com.squareup.wire.Syntax) ServiceDefinition(io.confluent.kafka.schemaregistry.protobuf.dynamic.ServiceDefinition)

Aggregations

EnumElement (com.squareup.wire.schema.internal.parser.EnumElement)26 MessageElement (com.squareup.wire.schema.internal.parser.MessageElement)23 TypeElement (com.squareup.wire.schema.internal.parser.TypeElement)22 OptionElement (com.squareup.wire.schema.internal.parser.OptionElement)18 ServiceElement (com.squareup.wire.schema.internal.parser.ServiceElement)17 HashSet (java.util.HashSet)16 ImmutableList (com.google.common.collect.ImmutableList)14 EnumValueDescriptorProto (com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto)14 ProtoFileElement (com.squareup.wire.schema.internal.parser.ProtoFileElement)14 EnumConstantElement (com.squareup.wire.schema.internal.parser.EnumConstantElement)13 FieldElement (com.squareup.wire.schema.internal.parser.FieldElement)13 OneOfElement (com.squareup.wire.schema.internal.parser.OneOfElement)13 ReservedElement (com.squareup.wire.schema.internal.parser.ReservedElement)13 Syntax (com.squareup.wire.Syntax)12 RpcElement (com.squareup.wire.schema.internal.parser.RpcElement)12 DescriptorProto (com.google.protobuf.DescriptorProtos.DescriptorProto)11 EnumDescriptorProto (com.google.protobuf.DescriptorProtos.EnumDescriptorProto)11 FieldDescriptorProto (com.google.protobuf.DescriptorProtos.FieldDescriptorProto)11 FileDescriptorProto (com.google.protobuf.DescriptorProtos.FileDescriptorProto)11 MethodDescriptorProto (com.google.protobuf.DescriptorProtos.MethodDescriptorProto)11