本文整理汇总了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);
}
示例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);
}
示例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);
}