Search in sources :

Example 1 with EnumDescriptorProto

use of com.google.protobuf.DescriptorProtos.EnumDescriptorProto in project java-bigquerystorage by googleapis.

the class ProtoSchemaConverter method convertInternal.

private static ProtoSchema convertInternal(Descriptor input, Set<String> visitedTypes, Set<String> enumTypes, Set<String> structTypes, DescriptorProto.Builder rootProtoSchema) {
    DescriptorProto.Builder resultProto = DescriptorProto.newBuilder();
    if (rootProtoSchema == null) {
        rootProtoSchema = resultProto;
    }
    String protoFullName = input.getFullName();
    String protoName = getNameFromFullName(protoFullName);
    resultProto.setName(protoName);
    Set<String> localEnumTypes = new HashSet<String>();
    visitedTypes.add(input.getFullName());
    for (int i = 0; i < input.getFields().size(); i++) {
        FieldDescriptor inputField = input.getFields().get(i);
        FieldDescriptorProto.Builder resultField = inputField.toProto().toBuilder();
        if (inputField.getType() == FieldDescriptor.Type.GROUP || inputField.getType() == FieldDescriptor.Type.MESSAGE) {
            String msgFullName = inputField.getMessageType().getFullName();
            String msgName = getNameFromFullName(msgFullName);
            if (structTypes.contains(msgFullName)) {
                resultField.setTypeName(msgName);
            } else {
                if (visitedTypes.contains(msgFullName)) {
                    throw new InvalidArgumentException("Recursive type is not supported:" + inputField.getMessageType().getFullName(), null, GrpcStatusCode.of(Status.Code.INVALID_ARGUMENT), false);
                }
                visitedTypes.add(msgFullName);
                rootProtoSchema.addNestedType(convertInternal(inputField.getMessageType(), visitedTypes, enumTypes, structTypes, rootProtoSchema).getProtoDescriptor());
                visitedTypes.remove(msgFullName);
                resultField.setTypeName(rootProtoSchema.getNestedType(rootProtoSchema.getNestedTypeCount() - 1).getName());
            }
        }
        if (inputField.getType() == FieldDescriptor.Type.ENUM) {
            // For enums, in order to avoid value conflict, we will always define
            // a enclosing struct called enum_full_name_E that includes the actual
            // enum.
            String enumFullName = inputField.getEnumType().getFullName();
            String enclosingTypeName = getNameFromFullName(enumFullName) + "_E";
            String enumName = inputField.getEnumType().getName();
            String actualEnumFullName = enclosingTypeName + "." + enumName;
            if (enumTypes.contains(enumFullName)) {
                resultField.setTypeName(actualEnumFullName);
            } else {
                EnumDescriptorProto enumType = inputField.getEnumType().toProto();
                resultProto.addNestedType(DescriptorProto.newBuilder().setName(enclosingTypeName).addEnumType(enumType.toBuilder().setName(enumName)).build());
                resultField.setTypeName(actualEnumFullName);
                enumTypes.add(enumFullName);
            }
        }
        resultProto.addField(resultField);
    }
    structTypes.add(protoFullName);
    return ProtoSchema.newBuilder().setProtoDescriptor(resultProto.build()).build();
}
Also used : EnumDescriptorProto(com.google.protobuf.DescriptorProtos.EnumDescriptorProto) InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) FieldDescriptorProto(com.google.protobuf.DescriptorProtos.FieldDescriptorProto) EnumDescriptorProto(com.google.protobuf.DescriptorProtos.EnumDescriptorProto) DescriptorProto(com.google.protobuf.DescriptorProtos.DescriptorProto) FieldDescriptorProto(com.google.protobuf.DescriptorProtos.FieldDescriptorProto) HashSet(java.util.HashSet) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 2 with EnumDescriptorProto

use of com.google.protobuf.DescriptorProtos.EnumDescriptorProto in project hadoop by apache.

the class TestRPC method testCallsInternal.

private void testCallsInternal(Configuration conf) throws IOException {
    Server server = new RPC.Builder(conf).setProtocol(TestProtocol.class).setInstance(new TestImpl()).setBindAddress(ADDRESS).setPort(0).build();
    TestProtocol proxy = null;
    try {
        server.start();
        InetSocketAddress addr = NetUtils.getConnectAddress(server);
        proxy = RPC.getProxy(TestProtocol.class, TestProtocol.versionID, addr, conf);
        proxy.ping();
        String stringResult = proxy.echo("foo");
        assertEquals(stringResult, "foo");
        stringResult = proxy.echo((String) null);
        assertEquals(stringResult, null);
        // Check rpcMetrics
        MetricsRecordBuilder rb = getMetrics(server.rpcMetrics.name());
        assertCounter("RpcProcessingTimeNumOps", 3L, rb);
        assertCounterGt("SentBytes", 0L, rb);
        assertCounterGt("ReceivedBytes", 0L, rb);
        // Number of calls to echo method should be 2
        rb = getMetrics(server.rpcDetailedMetrics.name());
        assertCounter("EchoNumOps", 2L, rb);
        // Number of calls to ping method should be 1
        assertCounter("PingNumOps", 1L, rb);
        String[] stringResults = proxy.echo(new String[] { "foo", "bar" });
        assertTrue(Arrays.equals(stringResults, new String[] { "foo", "bar" }));
        stringResults = proxy.echo((String[]) null);
        assertTrue(Arrays.equals(stringResults, null));
        UTF8 utf8Result = (UTF8) proxy.echo(new UTF8("hello world"));
        assertEquals(new UTF8("hello world"), utf8Result);
        utf8Result = (UTF8) proxy.echo((UTF8) null);
        assertEquals(null, utf8Result);
        int intResult = proxy.add(1, 2);
        assertEquals(intResult, 3);
        intResult = proxy.add(new int[] { 1, 2 });
        assertEquals(intResult, 3);
        // Test protobufs
        EnumDescriptorProto sendProto = EnumDescriptorProto.newBuilder().setName("test").build();
        EnumDescriptorProto retProto = proxy.exchangeProto(sendProto);
        assertEquals(sendProto, retProto);
        assertNotSame(sendProto, retProto);
        boolean caught = false;
        try {
            proxy.error();
        } catch (IOException e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Caught " + e);
            }
            caught = true;
        }
        assertTrue(caught);
        rb = getMetrics(server.rpcDetailedMetrics.name());
        assertCounter("IOExceptionNumOps", 1L, rb);
        proxy.testServerGet();
        // create multiple threads and make them do large data transfers
        System.out.println("Starting multi-threaded RPC test...");
        server.setSocketSendBufSize(1024);
        Thread[] threadId = new Thread[numThreads];
        for (int i = 0; i < numThreads; i++) {
            Transactions trans = new Transactions(proxy, datasize);
            threadId[i] = new Thread(trans, "TransactionThread-" + i);
            threadId[i].start();
        }
        // wait for all transactions to get over
        System.out.println("Waiting for all threads to finish RPCs...");
        for (int i = 0; i < numThreads; i++) {
            try {
                threadId[i].join();
            } catch (InterruptedException e) {
                // retry
                i--;
            }
        }
    } finally {
        server.stop();
        if (proxy != null)
            RPC.stopProxy(proxy);
    }
}
Also used : EnumDescriptorProto(com.google.protobuf.DescriptorProtos.EnumDescriptorProto) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) UTF8(org.apache.hadoop.io.UTF8) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder)

Example 3 with EnumDescriptorProto

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

the class FileDescriptorUtils method toFileDescriptorProto.

private static FileDescriptorProto toFileDescriptorProto(String schemaDefinition, String protoFileName, Optional<String> optionalPackageName) {
    final ProtobufSchemaLoader.ProtobufSchemaLoaderContext protobufSchemaLoaderContext;
    try {
        protobufSchemaLoaderContext = ProtobufSchemaLoader.loadSchema(optionalPackageName, protoFileName, schemaDefinition);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    FileDescriptorProto.Builder schema = FileDescriptorProto.newBuilder();
    ProtoFile element = protobufSchemaLoaderContext.getProtoFile();
    Schema schemaContext = protobufSchemaLoaderContext.getSchema();
    schema.setName(protoFileName);
    Syntax syntax = element.getSyntax();
    if (Syntax.PROTO_3.equals(syntax)) {
        schema.setSyntax(syntax.toString());
    }
    if (element.getPackageName() != null) {
        schema.setPackage(element.getPackageName());
    }
    for (ProtoType protoType : schemaContext.getTypes()) {
        if (!isParentLevelType(protoType, optionalPackageName)) {
            continue;
        }
        Type type = schemaContext.getType(protoType);
        if (type instanceof MessageType) {
            DescriptorProto message = messageElementToDescriptorProto((MessageType) type, schemaContext, element);
            schema.addMessageType(message);
        } else if (type instanceof EnumType) {
            EnumDescriptorProto message = enumElementToProto((EnumType) type);
            schema.addEnumType(message);
        }
    }
    for (Service service : element.getServices()) {
        ServiceDescriptorProto serviceDescriptorProto = serviceElementToProto(service);
        schema.addService(serviceDescriptorProto);
    }
    // dependencies on protobuf default types are always added
    for (String ref : element.getImports()) {
        schema.addDependency(ref);
    }
    for (String ref : element.getPublicImports()) {
        boolean add = true;
        for (int i = 0; i < schema.getDependencyCount(); i++) {
            if (schema.getDependency(i).equals(ref)) {
                schema.addPublicDependency(i);
                add = false;
            }
        }
        if (add) {
            schema.addDependency(ref);
            schema.addPublicDependency(schema.getDependencyCount() - 1);
        }
    }
    String javaPackageName = findOptionString(JAVA_PACKAGE_OPTION, element.getOptions());
    if (javaPackageName != null) {
        FileOptions options = DescriptorProtos.FileOptions.newBuilder().setJavaPackage(javaPackageName).build();
        schema.mergeOptions(options);
    }
    String javaOuterClassname = findOptionString(JAVA_OUTER_CLASSNAME_OPTION, element.getOptions());
    if (javaOuterClassname != null) {
        FileOptions options = DescriptorProtos.FileOptions.newBuilder().setJavaOuterClassname(javaOuterClassname).build();
        schema.mergeOptions(options);
    }
    Boolean javaMultipleFiles = findOptionBoolean(JAVA_MULTIPLE_FILES_OPTION, element.getOptions());
    if (javaMultipleFiles != null) {
        FileOptions options = DescriptorProtos.FileOptions.newBuilder().setJavaMultipleFiles(javaMultipleFiles).build();
        schema.mergeOptions(options);
    }
    Boolean javaStringCheckUtf8 = findOptionBoolean(JAVA_STRING_CHECK_UTF8_OPTION, element.getOptions());
    if (javaStringCheckUtf8 != null) {
        FileOptions options = DescriptorProtos.FileOptions.newBuilder().setJavaStringCheckUtf8(javaStringCheckUtf8).build();
        schema.mergeOptions(options);
    }
    Boolean javaGenericServices = findOptionBoolean(JAVA_GENERIC_SERVICES_OPTION, element.getOptions());
    if (javaGenericServices != null) {
        FileOptions options = DescriptorProtos.FileOptions.newBuilder().setJavaGenericServices(javaGenericServices).build();
        schema.mergeOptions(options);
    }
    Boolean ccGenericServices = findOptionBoolean(CC_GENERIC_SERVICES_OPTION, element.getOptions());
    if (ccGenericServices != null) {
        FileOptions options = DescriptorProtos.FileOptions.newBuilder().setCcGenericServices(ccGenericServices).build();
        schema.mergeOptions(options);
    }
    Boolean ccEnableArenas = findOptionBoolean(CC_ENABLE_ARENAS_OPTION, element.getOptions());
    if (ccEnableArenas != null) {
        FileOptions options = DescriptorProtos.FileOptions.newBuilder().setCcEnableArenas(ccEnableArenas).build();
        schema.mergeOptions(options);
    }
    String csharpNamespace = findOptionString(CSHARP_NAMESPACE_OPTION, element.getOptions());
    if (csharpNamespace != null) {
        FileOptions options = DescriptorProtos.FileOptions.newBuilder().setCsharpNamespace(csharpNamespace).build();
        schema.mergeOptions(options);
    }
    String goPackageName = findOptionString(GO_PACKAGE_OPTION, element.getOptions());
    if (goPackageName != null) {
        FileOptions options = DescriptorProtos.FileOptions.newBuilder().setGoPackage(goPackageName).build();
        schema.mergeOptions(options);
    }
    String objcClassPrefix = findOptionString(OBJC_CLASS_PREFIX_OPTION, element.getOptions());
    if (objcClassPrefix != null) {
        FileOptions options = DescriptorProtos.FileOptions.newBuilder().setObjcClassPrefix(objcClassPrefix).build();
        schema.mergeOptions(options);
    }
    Boolean phpGenericServices = findOptionBoolean(PHP_GENERIC_SERVICES_OPTION, element.getOptions());
    if (phpGenericServices != null) {
        FileOptions options = DescriptorProtos.FileOptions.newBuilder().setPhpGenericServices(phpGenericServices).build();
        schema.mergeOptions(options);
    }
    String phpClassPrefix = findOptionString(PHP_CLASS_PREFIX_OPTION, element.getOptions());
    if (phpClassPrefix != null) {
        FileOptions options = DescriptorProtos.FileOptions.newBuilder().setPhpClassPrefix(phpClassPrefix).build();
        schema.mergeOptions(options);
    }
    String phpMetadataNamespace = findOptionString(PHP_METADATA_NAMESPACE_OPTION, element.getOptions());
    if (phpMetadataNamespace != null) {
        FileOptions options = DescriptorProtos.FileOptions.newBuilder().setPhpMetadataNamespace(phpMetadataNamespace).build();
        schema.mergeOptions(options);
    }
    String phpNamespace = findOptionString(PHP_NAMESPACE_OPTION, element.getOptions());
    if (phpNamespace != null) {
        FileOptions options = DescriptorProtos.FileOptions.newBuilder().setPhpNamespace(phpNamespace).build();
        schema.mergeOptions(options);
    }
    Boolean pyGenericServices = findOptionBoolean(PY_GENERIC_SERVICES_OPTION, element.getOptions());
    if (pyGenericServices != null) {
        FileOptions options = DescriptorProtos.FileOptions.newBuilder().setPyGenericServices(pyGenericServices).build();
        schema.mergeOptions(options);
    }
    String rubyPackage = findOptionString(RUBY_PACKAGE_OPTION, element.getOptions());
    if (rubyPackage != null) {
        FileOptions options = DescriptorProtos.FileOptions.newBuilder().setRubyPackage(rubyPackage).build();
        schema.mergeOptions(options);
    }
    String swiftPrefix = findOptionString(SWIFT_PREFIX_OPTION, element.getOptions());
    if (swiftPrefix != null) {
        FileOptions options = DescriptorProtos.FileOptions.newBuilder().setSwiftPrefix(swiftPrefix).build();
        schema.mergeOptions(options);
    }
    FileOptions.OptimizeMode optimizeFor = findOption(OPTIMIZE_FOR_OPTION, element.getOptions()).map(o -> FileOptions.OptimizeMode.valueOf(o.getValue().toString())).orElse(null);
    if (optimizeFor != null) {
        FileOptions options = DescriptorProtos.FileOptions.newBuilder().setOptimizeFor(optimizeFor).build();
        schema.mergeOptions(options);
    }
    return schema.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) EnumDescriptorProto(com.google.protobuf.DescriptorProtos.EnumDescriptorProto) ServiceDescriptorProto(com.google.protobuf.DescriptorProtos.ServiceDescriptorProto) Schema(com.squareup.wire.schema.Schema) ProtoFile(com.squareup.wire.schema.ProtoFile) Service(com.squareup.wire.schema.Service) DescriptorValidationException(com.google.protobuf.Descriptors.DescriptorValidationException) ProtoType(com.squareup.wire.schema.ProtoType) Type(com.squareup.wire.schema.Type) ProtoType(com.squareup.wire.schema.ProtoType) MessageType(com.squareup.wire.schema.MessageType) EnumType(com.squareup.wire.schema.EnumType) EnumType(com.squareup.wire.schema.EnumType) 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) Syntax(com.squareup.wire.Syntax) FileDescriptorProto(com.google.protobuf.DescriptorProtos.FileDescriptorProto) MessageType(com.squareup.wire.schema.MessageType) FileOptions(com.google.protobuf.DescriptorProtos.FileOptions)

Example 4 with EnumDescriptorProto

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

the class FileDescriptorUtils method fileDescriptorToProtoFile.

public static ProtoFileElement fileDescriptorToProtoFile(FileDescriptorProto file) {
    String packageName = file.getPackage();
    if ("".equals(packageName)) {
        packageName = null;
    }
    Syntax syntax = null;
    switch(file.getSyntax()) {
        case PROTO2:
            syntax = Syntax.PROTO_2;
            break;
        case PROTO3:
            syntax = Syntax.PROTO_3;
            break;
        default:
            break;
    }
    ImmutableList.Builder<TypeElement> types = ImmutableList.builder();
    for (DescriptorProto md : file.getMessageTypeList()) {
        MessageElement message = toMessage(file, md);
        types.add(message);
    }
    for (EnumDescriptorProto ed : file.getEnumTypeList()) {
        EnumElement enumer = toEnum(ed);
        types.add(enumer);
    }
    ImmutableList.Builder<ServiceElement> services = ImmutableList.builder();
    for (ServiceDescriptorProto sv : file.getServiceList()) {
        ServiceElement service = toService(sv);
        services.add(service);
    }
    ImmutableList.Builder<String> imports = ImmutableList.builder();
    ImmutableList.Builder<String> publicImports = ImmutableList.builder();
    List<String> dependencyList = file.getDependencyList();
    Set<Integer> publicDependencyList = new HashSet<>(file.getPublicDependencyList());
    for (int i = 0; i < dependencyList.size(); i++) {
        String depName = dependencyList.get(i);
        if (publicDependencyList.contains(i)) {
            publicImports.add(depName);
        } else {
            imports.add(depName);
        }
    }
    ImmutableList.Builder<OptionElement> options = ImmutableList.builder();
    if (file.getOptions().hasJavaPackage()) {
        OptionElement option = new OptionElement(JAVA_PACKAGE_OPTION, stringKind, file.getOptions().getJavaPackage(), false);
        options.add(option);
    }
    if (file.getOptions().hasJavaOuterClassname()) {
        OptionElement option = new OptionElement(JAVA_OUTER_CLASSNAME_OPTION, stringKind, file.getOptions().getJavaOuterClassname(), false);
        options.add(option);
    }
    if (file.getOptions().hasJavaMultipleFiles()) {
        OptionElement option = new OptionElement(JAVA_MULTIPLE_FILES_OPTION, booleanKind, file.getOptions().getJavaMultipleFiles(), false);
        options.add(option);
    }
    if (file.getOptions().hasJavaGenericServices()) {
        OptionElement option = new OptionElement(JAVA_GENERIC_SERVICES_OPTION, booleanKind, file.getOptions().getJavaGenericServices(), false);
        options.add(option);
    }
    if (file.getOptions().hasJavaStringCheckUtf8()) {
        OptionElement option = new OptionElement(JAVA_STRING_CHECK_UTF8_OPTION, booleanKind, file.getOptions().getJavaStringCheckUtf8(), false);
        options.add(option);
    }
    if (file.getOptions().hasCcGenericServices()) {
        OptionElement option = new OptionElement(CC_GENERIC_SERVICES_OPTION, booleanKind, file.getOptions().getCcGenericServices(), false);
        options.add(option);
    }
    if (file.getOptions().hasCcEnableArenas()) {
        OptionElement option = new OptionElement(CC_ENABLE_ARENAS_OPTION, booleanKind, file.getOptions().getCcEnableArenas(), false);
        options.add(option);
    }
    if (file.getOptions().hasCsharpNamespace()) {
        OptionElement option = new OptionElement(CSHARP_NAMESPACE_OPTION, stringKind, file.getOptions().getCsharpNamespace(), false);
        options.add(option);
    }
    if (file.getOptions().hasGoPackage()) {
        OptionElement option = new OptionElement(GO_PACKAGE_OPTION, stringKind, file.getOptions().getGoPackage(), false);
        options.add(option);
    }
    if (file.getOptions().hasObjcClassPrefix()) {
        OptionElement option = new OptionElement(OBJC_CLASS_PREFIX_OPTION, stringKind, file.getOptions().getObjcClassPrefix(), false);
        options.add(option);
    }
    if (file.getOptions().hasPhpClassPrefix()) {
        OptionElement option = new OptionElement(PHP_CLASS_PREFIX_OPTION, stringKind, file.getOptions().getPhpClassPrefix(), false);
        options.add(option);
    }
    if (file.getOptions().hasPhpGenericServices()) {
        OptionElement option = new OptionElement(PHP_GENERIC_SERVICES_OPTION, booleanKind, file.getOptions().getPhpGenericServices(), false);
        options.add(option);
    }
    if (file.getOptions().hasPhpMetadataNamespace()) {
        OptionElement option = new OptionElement(PHP_METADATA_NAMESPACE_OPTION, stringKind, file.getOptions().getPhpMetadataNamespace(), false);
        options.add(option);
    }
    if (file.getOptions().hasPhpNamespace()) {
        OptionElement option = new OptionElement(PHP_NAMESPACE_OPTION, stringKind, file.getOptions().getPhpNamespace(), false);
        options.add(option);
    }
    if (file.getOptions().hasPyGenericServices()) {
        OptionElement option = new OptionElement(PY_GENERIC_SERVICES_OPTION, booleanKind, file.getOptions().getPyGenericServices(), false);
        options.add(option);
    }
    if (file.getOptions().hasRubyPackage()) {
        OptionElement option = new OptionElement(RUBY_PACKAGE_OPTION, stringKind, file.getOptions().getRubyPackage(), false);
        options.add(option);
    }
    if (file.getOptions().hasSwiftPrefix()) {
        OptionElement option = new OptionElement(SWIFT_PREFIX_OPTION, stringKind, file.getOptions().getSwiftPrefix(), false);
        options.add(option);
    }
    if (file.getOptions().hasOptimizeFor()) {
        OptionElement option = new OptionElement(OPTIMIZE_FOR_OPTION, enumKind, file.getOptions().getOptimizeFor(), false);
        options.add(option);
    }
    return new ProtoFileElement(DEFAULT_LOCATION, packageName, syntax, imports.build(), publicImports.build(), types.build(), services.build(), Collections.emptyList(), options.build());
}
Also used : EnumDescriptorProto(com.google.protobuf.DescriptorProtos.EnumDescriptorProto) ImmutableList(com.google.common.collect.ImmutableList) TypeElement(com.squareup.wire.schema.internal.parser.TypeElement) ServiceDescriptorProto(com.google.protobuf.DescriptorProtos.ServiceDescriptorProto) MessageElement(com.squareup.wire.schema.internal.parser.MessageElement) ProtoFileElement(com.squareup.wire.schema.internal.parser.ProtoFileElement) EnumElement(com.squareup.wire.schema.internal.parser.EnumElement) ServiceElement(com.squareup.wire.schema.internal.parser.ServiceElement) 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) Syntax(com.squareup.wire.Syntax) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 5 with EnumDescriptorProto

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

the class FileDescriptorUtils method enumElementToProto.

private static EnumDescriptorProto enumElementToProto(EnumType enumElem) {
    Boolean allowAlias = findOptionBoolean(ALLOW_ALIAS_OPTION, enumElem.getOptions());
    EnumDescriptorProto.Builder builder = EnumDescriptorProto.newBuilder().setName(enumElem.getName());
    if (allowAlias != null) {
        DescriptorProtos.EnumOptions.Builder optionsBuilder = DescriptorProtos.EnumOptions.newBuilder().setAllowAlias(allowAlias);
        builder.mergeOptions(optionsBuilder.build());
    }
    for (EnumConstant constant : enumElem.getConstants()) {
        builder.addValue(EnumValueDescriptorProto.newBuilder().setName(constant.getName()).setNumber(constant.getTag()).build());
    }
    return builder.build();
}
Also used : EnumDescriptorProto(com.google.protobuf.DescriptorProtos.EnumDescriptorProto) EnumConstant(com.squareup.wire.schema.EnumConstant)

Aggregations

EnumDescriptorProto (com.google.protobuf.DescriptorProtos.EnumDescriptorProto)14 DescriptorProto (com.google.protobuf.DescriptorProtos.DescriptorProto)10 FieldDescriptorProto (com.google.protobuf.DescriptorProtos.FieldDescriptorProto)10 HashSet (java.util.HashSet)10 ImmutableList (com.google.common.collect.ImmutableList)8 EnumValueDescriptorProto (com.google.protobuf.DescriptorProtos.EnumValueDescriptorProto)8 FileDescriptorProto (com.google.protobuf.DescriptorProtos.FileDescriptorProto)8 MethodDescriptorProto (com.google.protobuf.DescriptorProtos.MethodDescriptorProto)8 OneofDescriptorProto (com.google.protobuf.DescriptorProtos.OneofDescriptorProto)8 ServiceDescriptorProto (com.google.protobuf.DescriptorProtos.ServiceDescriptorProto)8 Syntax (com.squareup.wire.Syntax)8 EnumElement (com.squareup.wire.schema.internal.parser.EnumElement)8 MessageElement (com.squareup.wire.schema.internal.parser.MessageElement)8 OptionElement (com.squareup.wire.schema.internal.parser.OptionElement)8 ProtoFileElement (com.squareup.wire.schema.internal.parser.ProtoFileElement)8 ServiceElement (com.squareup.wire.schema.internal.parser.ServiceElement)8 TypeElement (com.squareup.wire.schema.internal.parser.TypeElement)8 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)7 LOWER_UNDERSCORE (com.google.common.base.CaseFormat.LOWER_UNDERSCORE)5 UPPER_CAMEL (com.google.common.base.CaseFormat.UPPER_CAMEL)5