本文整理汇总了Java中com.google.protobuf.ExtensionRegistry.getEmptyRegistry方法的典型用法代码示例。如果您正苦于以下问题:Java ExtensionRegistry.getEmptyRegistry方法的具体用法?Java ExtensionRegistry.getEmptyRegistry怎么用?Java ExtensionRegistry.getEmptyRegistry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.ExtensionRegistry
的用法示例。
在下文中一共展示了ExtensionRegistry.getEmptyRegistry方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Builder
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
private Builder() {
protocCompatible = false;
customOptionsAsExtensions = true;
registry = ExtensionRegistry.getEmptyRegistry();
fileDescriptor = null;
proto = null;
dependencies = new ArrayList<FileDescriptor>();
isBuilt = false;
}
示例2: testMergeCharSequenceExtensionRegistryBuilder
import com.google.protobuf.ExtensionRegistry; //导入方法依赖的package包/类
@Test
public void testMergeCharSequenceExtensionRegistryBuilder() throws ParseException,
URISyntaxException {
final Map<String, FileDescriptor> info1 =
ProtoFiles
.newBuilder()
.addFiles(new File(getClass().getResource("protoc-misc/").toURI()),
"DeepAggregateOptionValue1.proto").build();
final String protoSource =
new StringBuilder().append("message Message1 {").append(NL)
.append(" optional string f1 = 1;").append(NL).append(" optional Message2 f2 = 2;")
.append(NL).append("}").append(NL).append("").append(NL).append("message Message2 {")
.append(NL).append(" optional string f21 = 1;").append(NL)
.append(" optional string f22 = 2;").append(NL).append("}").append(NL).toString();
final Map<String, FileDescriptor> info =
ProtoFiles.newBuilder().addSource("DeepAggregateOptionValue1.proto", protoSource).build();
final Descriptor type =
info.get("DeepAggregateOptionValue1.proto").findMessageTypeByName("Message1");
final FieldDescriptor f1FD = type.findFieldByName("f1");
final FieldDescriptor f2FD = type.findFieldByName("f2");
final Descriptor type2 = f2FD.getMessageType();
final DynamicMessage expected =
DynamicMessage
.newBuilder(type)
.setField(f1FD, "hello")
.setField(
f2FD,
DynamicMessage.newBuilder(type2).setField(type2.findFieldByName("f21"), "deep1")
.setField(type2.findFieldByName("f22"), "deep2").build()).build();
final DynamicMessage.Builder builder = DynamicMessage.newBuilder(type);
final String input = "f1:'hello' f2 {f21:'deep1' f22:'deep2'}";
final ExtensionRegistry extensionRegistry = ExtensionRegistry.getEmptyRegistry();
TextFormat.merge(input, extensionRegistry, builder);
final DynamicMessage actual = builder.build();
assertThat(actual, equalTo(expected));
}