com.google.protobuf.ExtensionRegistry#add ( )源码实例Demo

下面列出了com.google.protobuf.ExtensionRegistry#add ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: bidder   文件: GoogleBidRequest.java
/**
 * Given the input stream, parse and make the class.
 * 
 * @param in InputStream. The content of the POST
 * @throws Exception on protobuf, json or I/O errors.
 */
public GoogleBidRequest(InputStream in) throws Exception {
	int nRead;
	byte[] data = new byte[1024];
	ByteArrayOutputStream buffer = new ByteArrayOutputStream();
	while ((nRead = in.read(data, 0, data.length)) != -1) {
		buffer.write(data, 0, nRead);
	}

	data = buffer.toByteArray();
	if (data.length == 0) {
		notABidRequest = true;
		return;
	}

	ExtensionRegistry registry = ExtensionRegistry.newInstance();
	registry.add(com.google.doubleclick.AdxExt.imp);
	internal = com.google.openrtb.OpenRtb.BidRequest.parseFrom(data, registry);

	// internal = com.google.openrtb.OpenRtb.BidRequest.parseFrom(in);
	doInternal();
}
 
public static ExtensionRegistry getInstance() {
  ExtensionRegistry extensionRegistry = ExtensionRegistry.newInstance();
  Iterable<FieldDescriptor> extensionDescriptors = Iterables.concat(
      AllExtensions.getDescriptor().getExtensions(),
      RepeatedExtensions.getDescriptor().getExtensions()
  );

  for (FieldDescriptor extension : extensionDescriptors) {
    if (extension.getJavaType() == JavaType.MESSAGE) {
      extensionRegistry.add(extension, Nested.getDefaultInstance());
    } else {
      extensionRegistry.add(extension);
    }
  }

  return extensionRegistry;
}
 
public void init(MarshallerReaderContext context) {
    ExtensionRegistry registry = (ExtensionRegistry) context.parameterObject;
    registry.add( JBPMMessages.processInstance );
    registry.add( JBPMMessages.processTimer );
    registry.add( JBPMMessages.procTimer );
    registry.add( JBPMMessages.workItem );
    registry.add( JBPMMessages.timerId );
}
 
源代码4 项目: datacollector   文件: ProtobufTestUtil.java
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;
}
 
源代码5 项目: j2objc   文件: CompatibilityTest.java
public void testMergeAndParseFromInputStream() throws Exception {
  ExtensionRegistry registry = ExtensionRegistry.newInstance();
  registry.add(Typical.myPrimitiveExtension);
  byte[] rawData = asBytes(new int[]{
      0x08, 0x06, 0x60, 0x01, 0x7A, 0x03, 0x62, 0x61, 0x72, 0xC8, 0x3E, 0x2D });
  checkMergeAndParse(
      TypicalData.newBuilder().mergeFrom(new ByteArrayInputStream(rawData), registry).build(),
      true);
  checkMergeAndParse(TypicalData.parseFrom(new ByteArrayInputStream(rawData), registry), true);

  // test API without ExtensionRegistry
  checkMergeAndParse(
      TypicalData.newBuilder().mergeFrom(new ByteArrayInputStream(rawData)).build(), false);
  checkMergeAndParse(TypicalData.parseFrom(new ByteArrayInputStream(rawData)), false);
}
 
源代码6 项目: j2objc   文件: CompatibilityTest.java
public void testExtensionRegistryGetUnmodifiable() throws Exception {
  ExtensionRegistry registry = ExtensionRegistry.newInstance();
  ExtensionRegistry registry2 = registry.getUnmodifiable();
  registry.add(Typical.myPrimitiveExtension);
  // Extension added to registry should be visible in registry2.
  Descriptor descriptor = TypicalData.getDescriptor();
  ExtensionRegistry.ExtensionInfo extensionInfo =
      registry2.findExtensionByNumber(descriptor, 1001);
  assertNotNull(extensionInfo);

  ExtensionRegistryLite registryLite = ExtensionRegistryLite.newInstance();
  ExtensionRegistryLite registryLite2 = registryLite.getUnmodifiable();
  assertNotNull(registryLite2);
}
 
源代码7 项目: spliceengine   文件: OlapPipelineFactory.java
private ExtensionRegistry buildExtensionRegistry(){
    ExtensionRegistry er = ExtensionRegistry.newInstance();
    er.add(OlapMessage.Submit.command);
    er.add(OlapMessage.Status.command);
    er.add(OlapMessage.Cancel.command);
    return er;
}
 
源代码8 项目: spliceengine   文件: AsyncOlapNIOLayer.java
private ExtensionRegistry buildExtensionRegistry(){
    ExtensionRegistry er=ExtensionRegistry.newInstance();
    er.add(OlapMessage.FailedResponse.response);
    er.add(OlapMessage.CancelledResponse.response);
    er.add(OlapMessage.ProgressResponse.response);
    er.add(OlapMessage.Result.response);
    return er;
}