Search in sources :

Example 1 with GenericDescriptor

use of com.google.protobuf.Descriptors.GenericDescriptor in project core-java by SpineEventEngine.

the class KnownTypes method getDescriptor.

/**
     * Retrieve {@link Descriptors proto descriptor} from the type name.
     *
     * @param typeName <b>valid</b> name of the desired type
     * @return {@link Descriptors proto descriptor} for given type
     * @see TypeName
     * @throws IllegalArgumentException if the name does not correspond to any known type
     */
static GenericDescriptor getDescriptor(String typeName) {
    final TypeUrl typeUrl = getTypeUrl(typeName);
    checkArgument(typeUrl != null, "Given type name is invalid");
    final Class<?> cls = getJavaClass(typeUrl);
    final GenericDescriptor descriptor;
    try {
        final java.lang.reflect.Method descriptorGetter = cls.getDeclaredMethod(METHOD_GET_DESCRIPTOR);
        descriptor = (GenericDescriptor) descriptorGetter.invoke(null);
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        throw newIllegalStateException(e, "Unable to get descriptor for the type %s", typeName);
    }
    return descriptor;
}
Also used : GenericDescriptor(com.google.protobuf.Descriptors.GenericDescriptor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with GenericDescriptor

use of com.google.protobuf.Descriptors.GenericDescriptor in project beam by apache.

the class ProtobufUtil method checkProto2Syntax.

/**
   * Recursively walks the given {@link Message} class and verifies that every field or message
   * linked in uses the Protocol Buffers proto2 syntax.
   */
static void checkProto2Syntax(Class<? extends Message> clazz, ExtensionRegistry registry) {
    for (GenericDescriptor d : getRecursiveDescriptorsForClass(clazz, registry)) {
        Syntax s = d.getFile().getSyntax();
        checkArgument(s == Syntax.PROTO2, "Message %s or one of its dependencies does not use proto2 syntax: %s in file %s", clazz.getName(), d.getFullName(), d.getFile().getName());
    }
}
Also used : GenericDescriptor(com.google.protobuf.Descriptors.GenericDescriptor) Syntax(com.google.protobuf.Descriptors.FileDescriptor.Syntax)

Aggregations

GenericDescriptor (com.google.protobuf.Descriptors.GenericDescriptor)2 Syntax (com.google.protobuf.Descriptors.FileDescriptor.Syntax)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1