本文整理汇总了Java中com.google.protobuf.ExtensionRegistry.newInstance方法的典型用法代码示例。如果您正苦于以下问题:Java ExtensionRegistry.newInstance方法的具体用法?Java ExtensionRegistry.newInstance怎么用?Java ExtensionRegistry.newInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.ExtensionRegistry
的用法示例。
在下文中一共展示了ExtensionRegistry.newInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getExtensionRegistry
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
/**
* Returns the {@link ExtensionRegistry} listing all known Protocol Buffers extension messages
* to {@code T} registered with this {@link ProtoCoder}.
*/
public ExtensionRegistry getExtensionRegistry() {
if (memoizedExtensionRegistry == null) {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
for (Class<?> extensionHost : extensionHostClasses) {
try {
extensionHost
.getDeclaredMethod("registerAllExtensions", ExtensionRegistry.class)
.invoke(null, registry);
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new IllegalStateException(e);
}
}
memoizedExtensionRegistry = registry.getUnmodifiable();
}
return memoizedExtensionRegistry;
}
示例2: main
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
Options.registerAllExtensions(registry);
PluginProtos.CodeGeneratorRequest request = PluginProtos.CodeGeneratorRequest.
parseFrom(System.in, registry);
PluginProtos.CodeGeneratorResponse response;
try {
Scope<Object> root = buildScopeTree(request);
PluginProtos.CodeGeneratorResponse.Builder responseBuilder =
PluginProtos.CodeGeneratorResponse.newBuilder();
writeFiles(root, responseBuilder);
response = responseBuilder.build();
} catch (Exception e) {
// 出错,报告给 protoc ,然后退出
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
pw.flush();
PluginProtos.CodeGeneratorResponse.newBuilder().setError(sw.toString()).
build().writeTo(System.out);
System.out.flush();
return;
}
response.writeTo(System.out);
System.out.flush();
}
示例3: Xbuf
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
/**
* A full constructor that allow to define every service (to injection).
* @param assetManager the AssetManager used to load assets (texture, sound,...)
* @param registry the protobuf registry for extensions
* @param loader4Materials the xbuf way to load materials (null == use default implementation)
* @param loader4Relations the xbuf way to load relations (null == use default implementation)
*/
public Xbuf(AssetManager assetManager, ExtensionRegistry registry, MaterialsMerger loader4Materials, RelationsMerger loader4Relations){
loader4Materials = (loader4Materials != null) ?loader4Materials : new MaterialsMerger(assetManager);
loader4Relations = (loader4Relations != null) ?loader4Relations : new RelationsMerger(loader4Materials);
mergers=new LinkedList<Merger>();
mergers.add(new NodesMerger());
mergers.add(new MeshesMerger(loader4Materials));
mergers.add(loader4Materials);
mergers.add(new LightsMerger());
mergers.add(new SkeletonsMerger());
mergers.add(new AnimationsMerger());
mergers.add(new CustomParamsMerger());
mergers.add(new PhysicsMerger());
// relations should be the last because it reuse data provide by other (put in components)
mergers.add(loader4Relations);
this.registry=registry!=null?registry:ExtensionRegistry.newInstance();
setupExtensionRegistry(this.registry);
}
示例4: parseFrom
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
public static ValuePartition parseFrom(final byte[] bytes) throws DeserializationException {
ValuePartitionProtos.ValuePartition valuePartition = null;
try {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
registry
.add(org.apache.hadoop.hbase.index.protobuf.generated.ValuePartitionProtos.SpatialPartition.offset);
registry
.add(org.apache.hadoop.hbase.index.protobuf.generated.ValuePartitionProtos.SpatialPartition.length);
valuePartition =
ValuePartitionProtos.ValuePartition.newBuilder().mergeFrom(bytes, registry).build();
} catch (InvalidProtocolBufferException e) {
throw new DeserializationException(e);
}
return new SpatialPartition(
valuePartition
.getExtension(org.apache.hadoop.hbase.index.protobuf.generated.ValuePartitionProtos.SpatialPartition.offset),
valuePartition
.getExtension(org.apache.hadoop.hbase.index.protobuf.generated.ValuePartitionProtos.SpatialPartition.length));
}
示例5: parseFrom
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
public static ValuePartition parseFrom(final byte[] bytes) throws DeserializationException {
ValuePartitionProtos.ValuePartition valuePartition;
try {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
registry
.add(org.apache.hadoop.hbase.index.protobuf.generated.ValuePartitionProtos.SeparatorPartition.separator);
registry
.add(org.apache.hadoop.hbase.index.protobuf.generated.ValuePartitionProtos.SeparatorPartition.position);
valuePartition = ValuePartitionProtos.ValuePartition.parseFrom(bytes, registry);
} catch (InvalidProtocolBufferException e) {
throw new DeserializationException(e);
}
return new SeparatorPartition(
valuePartition
.getExtension(
org.apache.hadoop.hbase.index.protobuf.generated.ValuePartitionProtos.SeparatorPartition.separator)
.toByteArray(),
valuePartition
.getExtension(org.apache.hadoop.hbase.index.protobuf.generated.ValuePartitionProtos.SeparatorPartition.position));
}
示例6: ProtobufDataParserFactory
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
public ProtobufDataParserFactory(Settings settings) throws StageException {
super(settings);
this.protoDescriptorFile = settings.getConfig(ProtobufConstants.PROTO_DESCRIPTOR_FILE_KEY);
this.messageType = settings.getConfig(ProtobufConstants.MESSAGE_TYPE_KEY);
this.isDelimited = settings.getConfig(ProtobufConstants.DELIMITED_KEY);
messageTypeToExtensionMap = new HashMap<>();
defaultValueMap = new HashMap<>();
// Get the descriptor for the expected message type
descriptor = ProtobufTypeUtil.getDescriptor(
settings.getContext(),
protoDescriptorFile,
messageType,
messageTypeToExtensionMap,
defaultValueMap
);
// Build the extension registry based on the cached extension map
extensionRegistry = ExtensionRegistry.newInstance();
for(Map.Entry<String, Set<Descriptors.FieldDescriptor>> e : messageTypeToExtensionMap.entrySet()) {
Set<Descriptors.FieldDescriptor> value = e.getValue();
for (Descriptors.FieldDescriptor f : value) {
extensionRegistry.add(f);
}
}
}
示例7: setUp
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
@Before public void setUp() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(server.url("/"))
.addConverterFactory(ProtoConverterFactory.create())
.build();
service = retrofit.create(Service.class);
ExtensionRegistry registry = ExtensionRegistry.newInstance();
PhoneProtos.registerAllExtensions(registry);
Retrofit retrofitWithRegistry = new Retrofit.Builder()
.baseUrl(server.url("/"))
.addConverterFactory(ProtoConverterFactory.createWithRegistry(registry))
.build();
serviceWithRegistry = retrofitWithRegistry.create(ServiceWithRegistry.class);
}
示例8: getExtraActionInfo
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
public static ExtraActionInfo getExtraActionInfo(String extraActionFile) {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
ExtraActionsBase.registerAllExtensions(registry);
try (InputStream stream = Files.newInputStream(Paths.get(extraActionFile))) {
CodedInputStream coded = CodedInputStream.newInstance(stream);
return ExtraActionInfo.parseFrom(coded, registry);
} catch (IOException e) {
throw new RuntimeException("ERROR: failed to deserialize extra action file "
+ extraActionFile + ": " + e.getMessage(), e);
}
}
示例9: getStandardPlatformExtensions
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
/**
* Get the standard extension registry to use for processing service config. By default,
* registers extensions from {@code google/api/annotations.proto} (and related proto files).
*/
public static ExtensionRegistry getStandardPlatformExtensions() {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
AnnotationsProto.registerAllExtensions(registry);
return registry;
}
示例10: testRecursiveDescriptorsMessageCWithExtensions
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
@Test
public void testRecursiveDescriptorsMessageCWithExtensions() {
// With extensions, Message C has a reference to Message A and Message B.
ExtensionRegistry registry = ExtensionRegistry.newInstance();
Proto2CoderTestMessages.registerAllExtensions(registry);
assertThat(getRecursiveDescriptorFullNames(MessageC.class, registry), equalTo(MESSAGE_C_EXT));
}
示例11: getPipeline
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
/**
*
*/
public ChannelPipeline getPipeline() throws Exception
{
log.debug("getPipeline");
ChannelPipeline p = Channels.pipeline();
p.addLast("frameDecoder", new ProtobufVarint64FrameDecoder());
p.addLast("frameEncoder", new ProtobufVarint64LengthFieldPrepender());
ExtensionRegistry registry = ExtensionRegistry.newInstance();
InfoProtocol.registerAllExtensions(registry);
p.addLast("protobufDecoder",
new ProtobufDecoder(InfoProtocol.InfoReqPack.getDefaultInstance(), registry));
p.addLast("protobufEncoder", new ProtobufEncoder());
p.addLast("handler", new InfoChannelHandler());
return p;
}
示例12: createExtensionRegistry
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
public static ExtensionRegistry createExtensionRegistry(Map<String, Set<Descriptors.FieldDescriptor>> extensionMap) {
ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance();
for(Map.Entry<String, Set<Descriptors.FieldDescriptor>> e : extensionMap.entrySet()) {
Set<Descriptors.FieldDescriptor> value = e.getValue();
for (Descriptors.FieldDescriptor f : value) {
extensionRegistry.add(f);
}
}
return extensionRegistry;
}
示例13: checkProtobufDataUnknownFields
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
public static void checkProtobufDataUnknownFields(byte[] bytes) throws IOException {
ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance();
ExtensionsProto.registerAllExtensions(extensionRegistry);
ByteArrayInputStream bIn = new ByteArrayInputStream(bytes);
EmployeeProto.Employee.Builder builder = EmployeeProto.Employee.newBuilder();
EmployeeProto.Employee employee;
for(int i = 0; i < 10; i++) {
builder.mergeDelimitedFrom(bIn, extensionRegistry);
employee = builder.build();
PersonProto.Person person;
UnknownFieldsUtil.checkEmployeeUnknownFields(employee.getUnknownFields());
if( i % 2 == 0) {
EngineerProto.Engineer engineer = employee.getEngineer();
Assert.assertNotNull(engineer);
person = engineer.getPerson();
} else {
ExecutiveProto.Executive exec = employee.getExec();
Assert.assertNotNull(exec);
person = exec.getPerson();
}
Assert.assertNotNull(person);
UnknownFieldsUtil.checkPersonUnknownFields(person.getUnknownFields());
builder.clear();
}
}
示例14: readStudy
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
private Pair<BaseStudy, List<Attachment>> readStudy(InputStream inputStream) throws IOException {
Mica.StudyDto.Builder builder = Mica.StudyDto.newBuilder();
Readable input = new InputStreamReader(inputStream, Charsets.UTF_8);
ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance();
extensionRegistry .add(Mica.CollectionStudyDto.type);
extensionRegistry .add(Mica.HarmonizationStudyDto.type);
JsonFormat.merge(input, extensionRegistry, builder);
List<Attachment> atts = extractAttachments(builder);
BaseStudy study = dtos.fromDto( builder);
return Pair.create(study, atts);
}
示例15: buildExtensionRegistry
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
private ExtensionRegistry buildExtensionRegistry(){
ExtensionRegistry er = ExtensionRegistry.newInstance();
er.add(OlapMessage.Submit.command);
er.add(OlapMessage.Status.command);
er.add(OlapMessage.Cancel.command);
return er;
}