当前位置: 首页>>代码示例>>Java>>正文


Java FileDescriptor.findExtensionByName方法代码示例

本文整理汇总了Java中com.google.protobuf.Descriptors.FileDescriptor.findExtensionByName方法的典型用法代码示例。如果您正苦于以下问题:Java FileDescriptor.findExtensionByName方法的具体用法?Java FileDescriptor.findExtensionByName怎么用?Java FileDescriptor.findExtensionByName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.protobuf.Descriptors.FileDescriptor的用法示例。


在下文中一共展示了FileDescriptor.findExtensionByName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newFileScopedGeneratedExtension

import com.google.protobuf.Descriptors.FileDescriptor; //导入方法依赖的package包/类
/**
 * Used in proto1 generated code only.
 *
 * After enabling bridge, we can define proto2 extensions (the extended type
 * is a proto2 mutable message) in a proto1 .proto file. For these extensions
 * we should generate proto2 GeneratedExtensions.
 */
public static <ContainingType extends Message, Type>
   GeneratedExtension<ContainingType, Type>
   newFileScopedGeneratedExtension(
       final Class singularType, final Message defaultInstance,
       final String descriptorOuterClass, final String extensionName) {
  // For extensions scoped within a file, we load the descriptor outer
  // class and rely on it to get the FileDescriptor which then can be
  // used to obtain the extension's FieldDescriptor.
  return new GeneratedExtension<ContainingType, Type>(
      new CachedDescriptorRetriever() {
        protected FieldDescriptor loadDescriptor() {
          try {
            Class clazz =
                singularType.getClassLoader().loadClass(descriptorOuterClass);
            FileDescriptor file =
                (FileDescriptor) clazz.getField("descriptor").get(null);
            return file.findExtensionByName(extensionName);
          } catch (Exception e) {
            throw new RuntimeException(
                "Cannot load descriptors: " + descriptorOuterClass +
                " is not a valid descriptor class name", e);
          }
        }
      },
      singularType,
      defaultInstance,
      Extension.ExtensionType.MUTABLE);
}
 
开发者ID:reubenbrown13,项目名称:cfapi,代码行数:36,代码来源:GeneratedMessage.java

示例2: newFileScopedGeneratedExtension

import com.google.protobuf.Descriptors.FileDescriptor; //导入方法依赖的package包/类
/**
 * Used in proto1 generated code only.
 *
 * After enabling bridge, we can define proto2 extensions (the extended type
 * is a proto2 mutable message) in a proto1 .proto file. For these extensions
 * we should generate proto2 GeneratedExtensions.
 */
public static <ContainingType extends Message, Type>
   GeneratedExtension<ContainingType, Type>
   newFileScopedGeneratedExtension(
       final Class singularType, final Message defaultInstance,
       final String descriptorOuterClass, final String extensionName) {
  // For extensions scoped within a file, we load the descriptor outer
  // class and rely on it to get the FileDescriptor which then can be
  // used to obtain the extension's FieldDescriptor.
  return new GeneratedExtension<ContainingType, Type>(
      new CachedDescriptorRetriever() {
        @Override
        protected FieldDescriptor loadDescriptor() {
          try {
            Class clazz = singularType.getClassLoader().loadClass(descriptorOuterClass);
            FileDescriptor file = (FileDescriptor) clazz.getField("descriptor").get(null);
            return file.findExtensionByName(extensionName);
          } catch (Exception e) {
            throw new RuntimeException(
                "Cannot load descriptors: "
                    + descriptorOuterClass
                    + " is not a valid descriptor class name",
                e);
          }
        }
      },
      singularType,
      defaultInstance,
      Extension.ExtensionType.MUTABLE);
}
 
开发者ID:yeriomin,项目名称:play-store-api,代码行数:37,代码来源:GeneratedMessage.java

示例3: newFileScopedGeneratedExtension

import com.google.protobuf.Descriptors.FileDescriptor; //导入方法依赖的package包/类
/**
 * Used in proto1 generated code only.
 *
 * After enabling bridge, we can define proto2 extensions (the
 * extended type is a proto2 mutable message) in a proto1 .proto
 * file. For these extensions we should generate proto2
 * GeneratedExtensions.
 */
public static <ContainingType extends Message, Type>
        GeneratedExtension<ContainingType, Type>
        newFileScopedGeneratedExtension (
                final Class singularType, final Message defaultInstance,
                final String descriptorOuterClass, final String extensionName) {
            // For extensions scoped within a file, we load the descriptor outer
            // class and rely on it to get the FileDescriptor which then can be
            // used to obtain the extension's FieldDescriptor.
            return new GeneratedExtension<ContainingType, Type> (
                    new CachedDescriptorRetriever ()
                    {
                        protected FieldDescriptor loadDescriptor () {
                            try {
                                Class clazz
                                = singularType.getClassLoader ().loadClass (descriptorOuterClass);
                                FileDescriptor file
                                = (FileDescriptor) clazz.getField ("descriptor").get (null);
                                return file.findExtensionByName (extensionName);
                            } catch (Exception e) {
                                throw new RuntimeException (
                                        "Cannot load descriptors: " + descriptorOuterClass
                                        + " is not a valid descriptor class name", e);
                            }
                        }
                    },
                    singularType,
                    defaultInstance,
                    Extension.ExtensionType.MUTABLE);
        }
 
开发者ID:BFergerson,项目名称:Beam,代码行数:38,代码来源:GeneratedMessage.java


注:本文中的com.google.protobuf.Descriptors.FileDescriptor.findExtensionByName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。