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


Java ExtensionRegistry类代码示例

本文整理汇总了Java中com.google.protobuf.ExtensionRegistry的典型用法代码示例。如果您正苦于以下问题:Java ExtensionRegistry类的具体用法?Java ExtensionRegistry怎么用?Java ExtensionRegistry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: merge

import com.google.protobuf.ExtensionRegistry; //导入依赖的package包/类
/**
 * Parse a text-format message from {@code input} and merge the contents into {@code builder}.
 * Extensions will be recognized if they are registered in {@code extensionRegistry}.
 * @throws IOException
 */
public void merge(JsonParser parser,
						 ExtensionRegistry extensionRegistry,
                         Message.Builder builder) throws IOException {

    JsonToken token = parser.nextToken();
    if (token.equals(JsonToken.START_OBJECT)) {
    	token = parser.nextToken();
    }
    while (token != null && !token.equals(JsonToken.END_OBJECT)) {
    	mergeField(parser, extensionRegistry, builder);
    	token = parser.nextToken();
    }

    // Test to make sure the tokenizer has reached the end of the stream.
    if (parser.nextToken() != null) {
        throw new RuntimeException("Expecting the end of the stream, but there seems to be more data!  Check the input for a valid JSON format.");
    }
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:24,代码来源:JsonJacksonFormat.java

示例2: handleMissingField

import com.google.protobuf.ExtensionRegistry; //导入依赖的package包/类
private void handleMissingField(String fieldName, JsonParser parser,
                                       ExtensionRegistry extensionRegistry,
                                       UnknownFieldSet.Builder builder) throws IOException {

    JsonToken token = parser.nextToken();
    if (token.equals(JsonToken.START_OBJECT)) {
        // Message structure
    	token = parser.nextToken(); // skip name
    	while (token != null && !token.equals(JsonToken.END_OBJECT)) {
            handleMissingField(fieldName, parser, extensionRegistry, builder);
            token = parser.nextToken(); // get } or field name
        }
    } else if (token.equals(JsonToken.START_ARRAY)) {
        // Collection
        do {
            handleMissingField(fieldName, parser, extensionRegistry, builder);
            token = parser.getCurrentToken(); // got value or ]
        } while (token != null && !token.equals(JsonToken.END_ARRAY));
    } else {
        // Primitive value
    	// NULL, INT, BOOL, STRING
    	// nothing to do..
    }
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:25,代码来源:JsonJacksonFormat.java

示例3: handleValue

import com.google.protobuf.ExtensionRegistry; //导入依赖的package包/类
private void handleValue(JsonParser parser,
                                ExtensionRegistry extensionRegistry,
                                Message.Builder builder,
                                FieldDescriptor field,
                                ExtensionRegistry.ExtensionInfo extension,
                                boolean unknown) throws IOException {

    Object value = null;
    if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
        value = handleObject(parser, extensionRegistry, builder, field, extension, unknown);
    } else {
        value = handlePrimitive(parser, field);
    }
    if (value != null) {
        if (field.isRepeated()) {
            builder.addRepeatedField(field, value);
        } else {
            builder.setField(field, value);
        }
    }
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:22,代码来源:JsonJacksonFormat.java

示例4: merge

import com.google.protobuf.ExtensionRegistry; //导入依赖的package包/类
/**
 * Parse a text-format message from {@code input} and merge the contents into {@code builder}.
 * Extensions will be recognized if they are registered in {@code extensionRegistry}.
 */
public void merge(CharSequence input,
                         ExtensionRegistry extensionRegistry,
                         Message.Builder builder) throws ParseException {
    Tokenizer tokenizer = new Tokenizer(input);

    // Based on the state machine @ http://json.org/

    tokenizer.consume("{"); // Needs to happen when the object starts.
    while (!tokenizer.tryConsume("}")) { // Continue till the object is done
        mergeField(tokenizer, extensionRegistry, builder);
    }
    // Test to make sure the tokenizer has reached the end of the stream.
    if (!tokenizer.atEnd()) {
        throw tokenizer.parseException("Expecting the end of the stream, but there seems to be more data!  Check the input for a valid JSON format.");
    }
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:21,代码来源:JsonFormat.java

示例5: handleValue

import com.google.protobuf.ExtensionRegistry; //导入依赖的package包/类
private void handleValue(Tokenizer tokenizer,
                                ExtensionRegistry extensionRegistry,
                                Message.Builder builder,
                                FieldDescriptor field,
                                ExtensionRegistry.ExtensionInfo extension,
                                boolean unknown) throws ParseException {

    Object value = null;
    if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
        value = handleObject(tokenizer, extensionRegistry, builder, field, extension, unknown);
    } else {
        value = handlePrimitive(tokenizer, field);
    }
    if (value != null) {
        if (field.isRepeated()) {
            builder.addRepeatedField(field, value);
        } else {
            builder.setField(field, value);
        }
    }
}
 
开发者ID:jigsaw-projects,项目名称:jigsaw-payment,代码行数:22,代码来源:JsonFormat.java

示例6: withExtensionsFrom

import com.google.protobuf.ExtensionRegistry; //导入依赖的package包/类
/**
 * Returns a {@link ProtoCoder} like this one, but with the extensions from the given classes
 * registered.
 *
 * <p>Each of the extension host classes must be an class automatically generated by the
 * Protocol Buffers compiler, {@code protoc}, that contains messages.
 *
 * <p>Does not modify this object.
 */
public ProtoCoder<T> withExtensionsFrom(Iterable<Class<?>> moreExtensionHosts) {
  for (Class<?> extensionHost : moreExtensionHosts) {
    // Attempt to access the required method, to make sure it's present.
    try {
      Method registerAllExtensions =
          extensionHost.getDeclaredMethod("registerAllExtensions", ExtensionRegistry.class);
      checkArgument(
          Modifier.isStatic(registerAllExtensions.getModifiers()),
          "Method registerAllExtensions() must be static");
    } catch (NoSuchMethodException | SecurityException e) {
      throw new IllegalArgumentException(
          String.format("Unable to register extensions for %s", extensionHost.getCanonicalName()),
          e);
    }
  }

  return new ProtoCoder<>(
      protoMessageClass,
      new ImmutableSet.Builder<Class<?>>()
          .addAll(extensionHostClasses)
          .addAll(moreExtensionHosts)
          .build());
}
 
开发者ID:apache,项目名称:beam,代码行数:33,代码来源:ProtoCoder.java

示例7: 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;
}
 
开发者ID:apache,项目名称:beam,代码行数:21,代码来源:ProtoCoder.java

示例8: verifyDeterministic

import com.google.protobuf.ExtensionRegistry; //导入依赖的package包/类
/**
 * Recursively checks whether the specified class uses any Protocol Buffers fields that cannot
 * be deterministically encoded.
 *
 * @throws NonDeterministicException if the object cannot be encoded deterministically.
 */
static void verifyDeterministic(ProtoCoder<?> coder) throws NonDeterministicException {
  Class<? extends Message> message = coder.getMessageType();
  ExtensionRegistry registry = coder.getExtensionRegistry();
  Set<Descriptor> descriptors = getRecursiveDescriptorsForClass(message, registry);
  for (Descriptor d : descriptors) {
    for (FieldDescriptor fd : d.getFields()) {
      // If there is a transitively reachable Protocol Buffers map field, then this object cannot
      // be encoded deterministically.
      if (fd.isMapField()) {
        String reason =
            String.format(
                "Protocol Buffers message %s transitively includes Map field %s (from file %s)."
                    + " Maps cannot be deterministically encoded.",
                message.getName(),
                fd.getFullName(),
                fd.getFile().getFullName());
        throw new NonDeterministicException(coder, reason);
      }
    }
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:28,代码来源:ProtobufUtil.java

示例9: 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();
}
 
开发者ID:funkypandagame,项目名称:protoc-gen-as3,代码行数:27,代码来源:Main.java

示例10: 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);
}
 
开发者ID:xbuf,项目名称:jme3_xbuf,代码行数:27,代码来源:Xbuf.java

示例11: 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));
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:20,代码来源:SpatialPartition.java

示例12: 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));
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:21,代码来源:SeparatorPartition.java

示例13: ProtobufDataParser

import com.google.protobuf.ExtensionRegistry; //导入依赖的package包/类
public ProtobufDataParser(
    ProtoConfigurableEntity.Context context,
    String messageId,
    Descriptors.Descriptor descriptor,
    Map<String, Set<Descriptors.FieldDescriptor>> messageTypeToExtensionMap,
    ExtensionRegistry extensionRegistry,
    InputStream inputStream,
    String readerOffset,
    int maxObjectLength,
    boolean isDelimited
) throws IOException, Descriptors.DescriptorValidationException, DataParserException {
  this.context = context;
  this.inputStream = new OverrunInputStream(inputStream, maxObjectLength, true);
  this.messageId = messageId;
  this.messageTypeToExtensionMap = messageTypeToExtensionMap;
  this.extensionRegistry = extensionRegistry;
  this.descriptor = descriptor;
  this.builder = DynamicMessage.newBuilder(descriptor);
  this.isDelimited = isDelimited;

  // skip to the required location
  if (readerOffset != null && !readerOffset.isEmpty() && !readerOffset.equals("0")) {
    int offset = Integer.parseInt(readerOffset);
    this.inputStream.skip(offset);
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:27,代码来源:ProtobufDataParser.java

示例14: 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);
    }
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:26,代码来源:ProtobufDataParserFactory.java

示例15: createBinaryStream

import com.google.protobuf.ExtensionRegistry; //导入依赖的package包/类
public static <T extends GeneratedMessage> MessageInputStream<T> createBinaryStream(final InputStream is, String msgType) throws IOException {
    final Registry reg = Registry.getInstance();
    final ExtensionRegistry extReg = reg.getExtensionRegistry();
    final GeneratedMessage msg = reg.getInstanceForType(msgType);
    
    if (msg == null) {
        throw new RuntimeException("Type " + msgType + " not found.");
    }
    
    final Parser parser = msg.getParserForType();
    return new MessageInputStream<T>() {
        
        {
            next = readNext();
        }
        
        @Override
        protected T readNext()  throws IOException {
            if (is.available() > 0) {
                return (T) parser.parseDelimitedFrom(is, extReg);
            }
            return null;
        }
    };
}
 
开发者ID:temk,项目名称:protobuf-utils,代码行数:26,代码来源:MessageInputStream.java


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