com.google.protobuf.Message.getParserForType()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(233)

本文整理了Java中com.google.protobuf.Message.getParserForType()方法的一些代码示例,展示了Message.getParserForType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getParserForType()方法的具体详情如下:
包路径:com.google.protobuf.Message
类名称:Message
方法名:getParserForType

Message.getParserForType介绍

暂无

代码示例

代码示例来源:origin: org.apache.hadoop/hadoop-common

  1. @SuppressWarnings("unchecked")
  2. @Override
  3. <T> T readFrom(ByteBuffer bb) throws IOException {
  4. // using the parser with a byte[]-backed coded input stream is the
  5. // most efficient way to deserialize a protobuf. it has a direct
  6. // path to the PB ctor that doesn't create multi-layered streams
  7. // that internally buffer.
  8. CodedInputStream cis = CodedInputStream.newInstance(
  9. bb.array(), bb.position() + bb.arrayOffset(), bb.remaining());
  10. try {
  11. cis.pushLimit(cis.readRawVarint32());
  12. message = message.getParserForType().parseFrom(cis);
  13. cis.checkLastTagWas(0);
  14. } finally {
  15. // advance over the bytes read.
  16. bb.position(bb.position() + cis.getTotalBytesRead());
  17. }
  18. return (T)message;
  19. }
  20. }

代码示例来源:origin: com.google.protobuf/protobuf-java

  1. @java.lang.SuppressWarnings("unchecked")
  2. public <T extends com.google.protobuf.Message> T unpack(
  3. java.lang.Class<T> clazz)
  4. throws com.google.protobuf.InvalidProtocolBufferException {
  5. if (!is(clazz)) {
  6. throw new com.google.protobuf.InvalidProtocolBufferException(
  7. "Type of the Any message does not match the given class.");
  8. }
  9. if (cachedUnpackValue != null) {
  10. return (T) cachedUnpackValue;
  11. }
  12. T defaultInstance =
  13. com.google.protobuf.Internal.getDefaultInstance(clazz);
  14. T result = (T) defaultInstance.getParserForType()
  15. .parseFrom(getValue());
  16. cachedUnpackValue = result;
  17. return result;
  18. }
  19. public static final int TYPE_URL_FIELD_NUMBER = 1;

代码示例来源:origin: osmandapp/Osmand

  1. private static void eagerlyMergeMessageSetExtension(
  2. CodedInputStream input,
  3. ExtensionRegistry.ExtensionInfo extension,
  4. ExtensionRegistryLite extensionRegistry,
  5. Message.Builder builder,
  6. FieldSet<FieldDescriptor> extensions) throws IOException {
  7. FieldDescriptor field = extension.descriptor;
  8. Message value = null;
  9. if (hasOriginalMessage(builder, extensions, field)) {
  10. Message originalMessage =
  11. getOriginalMessage(builder, extensions, field);
  12. Message.Builder subBuilder = originalMessage.toBuilder();
  13. input.readMessage(subBuilder, extensionRegistry);
  14. value = subBuilder.buildPartial();
  15. } else {
  16. value = input.readMessage(extension.defaultInstance.getParserForType(),
  17. extensionRegistry);
  18. }
  19. if (builder != null) {
  20. builder.setField(field, value);
  21. } else {
  22. extensions.setField(field, value);
  23. }
  24. }

代码示例来源:origin: line/armeria

  1. final Message msg = prototype.getParserForType().parseFrom(stream);
  2. try {
  3. stream.checkLastTagWas(0);

代码示例来源:origin: osmandapp/Osmand

  1. value = subBuilder.buildPartial();
  2. } else {
  3. value = extension.defaultInstance.getParserForType()
  4. .parsePartialFrom(rawBytes, extensionRegistry);

代码示例来源:origin: baidu/brpc-java

  1. public static Message parseFrom(byte[] input, Message defaultInstance) throws IOException {
  2. return defaultInstance.getParserForType().parseFrom(input);
  3. }

代码示例来源:origin: com.baidu/brpc-java

  1. public static Message parseFrom(byte[] input, Message defaultInstance) throws IOException {
  2. return defaultInstance.getParserForType().parseFrom(input);
  3. }

代码示例来源:origin: com.baidu/brpc-java

  1. public Object inputDecode(byte[] input) throws IOException {
  2. return inputInstance.getParserForType().parseFrom(input);
  3. }

代码示例来源:origin: com.baidu/brpc-java

  1. public Object inputDecode(byte[] input, int offset, int len) throws IOException {
  2. return inputInstance.getParserForType().parseFrom(input, offset, len);
  3. }

代码示例来源:origin: baidu/brpc-java

  1. public Object inputDecode(byte[] input) throws IOException {
  2. return inputInstance.getParserForType().parseFrom(input);
  3. }

代码示例来源:origin: baidu/brpc-java

  1. public Object inputDecode(byte[] input, int offset, int len) throws IOException {
  2. return inputInstance.getParserForType().parseFrom(input, offset, len);
  3. }

代码示例来源:origin: com.baidu/brpc-java

  1. /**
  2. * parse proto from netty {@link ByteBuf}
  3. * @param input netty ByteBuf
  4. * @param defaultInstance default instance for proto
  5. * @return proto message
  6. * @throws IOException read io exception
  7. */
  8. public static Message parseFrom(ByteBuf input, Message defaultInstance) throws IOException {
  9. final int length = input.readableBytes();
  10. byte[] array = new byte[length];
  11. input.readBytes(array, 0, length);
  12. return defaultInstance.getParserForType().parseFrom(array);
  13. }

代码示例来源:origin: baidu/brpc-java

  1. /**
  2. * parse proto from netty {@link ByteBuf}
  3. * @param input netty ByteBuf
  4. * @param defaultInstance default instance for proto
  5. * @return proto message
  6. * @throws IOException read io exception
  7. */
  8. public static Message parseFrom(ByteBuf input, Message defaultInstance) throws IOException {
  9. final int length = input.readableBytes();
  10. byte[] array = new byte[length];
  11. input.readBytes(array, 0, length);
  12. return defaultInstance.getParserForType().parseFrom(array);
  13. }

代码示例来源:origin: org.apache.beam/beam-sdks-java-extensions-protobuf

  1. /** Get the memoized {@link Parser}, possibly initializing it lazily. */
  2. private Parser<T> getParser() {
  3. if (memoizedParser == null) {
  4. try {
  5. @SuppressWarnings("unchecked")
  6. T protoMessageInstance = (T) protoMessageClass.getMethod("getDefaultInstance").invoke(null);
  7. @SuppressWarnings("unchecked")
  8. Parser<T> tParser = (Parser<T>) protoMessageInstance.getParserForType();
  9. memoizedParser = tParser;
  10. } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
  11. throw new IllegalArgumentException(e);
  12. }
  13. }
  14. return memoizedParser;
  15. }

代码示例来源:origin: ks-no/eventstore2

  1. public static void registerDeserializeMethod(Message message, String type) {
  2. deserializeMethods.put(type, message.getParserForType());
  3. deserializeClasses.put(type, message.getClass());
  4. classToType.put(message.getClass(), type);
  5. }

代码示例来源:origin: baidu/brpc-java

  1. public static Message parseFrom(DynamicCompositeByteBuf input, Message defaultInstance) throws IOException {
  2. final byte[] array;
  3. final int offset;
  4. final int length = input.readableBytes();
  5. array = new byte[length];
  6. input.readBytes(array, 0, length);
  7. offset = 0;
  8. return defaultInstance.getParserForType().parseFrom(array, offset, length);
  9. }
  10. }

代码示例来源:origin: com.baidu/brpc-java

  1. public static Message parseFrom(DynamicCompositeByteBuf input, Message defaultInstance) throws IOException {
  2. final byte[] array;
  3. final int offset;
  4. final int length = input.readableBytes();
  5. array = new byte[length];
  6. input.readBytes(array, 0, length);
  7. offset = 0;
  8. return defaultInstance.getParserForType().parseFrom(array, offset, length);
  9. }
  10. }

代码示例来源:origin: io.hops/hadoop-common

  1. @SuppressWarnings("unchecked")
  2. @Override
  3. <T> T readFrom(ByteBuffer bb) throws IOException {
  4. // using the parser with a byte[]-backed coded input stream is the
  5. // most efficient way to deserialize a protobuf. it has a direct
  6. // path to the PB ctor that doesn't create multi-layered streams
  7. // that internally buffer.
  8. CodedInputStream cis = CodedInputStream.newInstance(
  9. bb.array(), bb.position() + bb.arrayOffset(), bb.remaining());
  10. try {
  11. cis.pushLimit(cis.readRawVarint32());
  12. message = message.getParserForType().parseFrom(cis);
  13. cis.checkLastTagWas(0);
  14. } finally {
  15. // advance over the bytes read.
  16. bb.position(bb.position() + cis.getTotalBytesRead());
  17. }
  18. return (T)message;
  19. }
  20. }

代码示例来源:origin: ks-no/eventstore2

  1. public static void registerDeserializeMethod(Message message) {
  2. deserializeMethods.put(message.getDescriptorForType().getFullName(), message.getParserForType());
  3. deserializeClasses.put(message.getDescriptorForType().getFullName(), message.getClass());
  4. classToType.put(message.getClass(), message.getDescriptorForType().getFullName());
  5. }

代码示例来源:origin: com.github.infogen7/infogen_soa

  1. @Override
  2. public void channelRead0(ChannelHandlerContext ctx, FullHttpResponse response) {
  3. HttpHeaders headers = response.headers();
  4. String sequence = headers.get(X_HttpHeaderNames.x_sequence.key);
  5. HttpResponseStatus status = response.status();
  6. int code = status.code();
  7. if (code == 100) {
  8. return;
  9. }
  10. if (sequence != null) {
  11. SimpleStatus simplestatus = map.get(Long.valueOf(sequence));
  12. if (simplestatus != null) {
  13. ByteBuf buf = response.content();
  14. byte[] resp = new byte[buf.readableBytes()];
  15. buf.readBytes(resp);
  16. try {
  17. simplestatus.callback.run(simplestatus.responsePrototype.getParserForType().parseFrom(resp));
  18. } catch (InvalidProtocolBufferException e) {
  19. LOGGER.error(e.getMessage(), e);
  20. simplestatus.controller.setFailed(e.getMessage());
  21. }
  22. }
  23. }
  24. }

相关文章