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


Java Parser.parseFrom方法代码示例

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


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

示例1: extract

import com.google.protobuf.Parser; //导入方法依赖的package包/类
/**
 * Attempts to extract a protocol buffer from the specified extra.
 * @throws MalformedDataException if the intent is null, the extra is missing or not a byte
 *     array, or the protocol buffer could not be parsed.
 */
@NonNull
public static <T extends MessageLite> T extract(
        @NonNull String extraName,
        @NonNull Parser<T> protoParser,
        @NonNull String failureDescription,
        @Nullable Intent intent)
        throws MalformedDataException {

    if (intent == null) {
        throw new MalformedDataException(failureDescription);
    }

    byte[] protoBytes = intent.getByteArrayExtra(extraName);
    if (protoBytes == null) {
        throw new MalformedDataException(failureDescription);
    }

    try {
        return protoParser.parseFrom(protoBytes);
    } catch (IOException ex) {
        throw new MalformedDataException(failureDescription, ex);
    }
}
 
开发者ID:openid,项目名称:OpenYOLO-Android,代码行数:29,代码来源:IntentProtocolBufferExtractor.java

示例2: toScanMetrics

import com.google.protobuf.Parser; //导入方法依赖的package包/类
public static ScanMetrics toScanMetrics(final byte[] bytes) {
  Parser<MapReduceProtos.ScanMetrics> parser = MapReduceProtos.ScanMetrics.PARSER;
  MapReduceProtos.ScanMetrics pScanMetrics = null;
  try {
    pScanMetrics = parser.parseFrom(bytes);
  } catch (InvalidProtocolBufferException e) {
    //Ignored there are just no key values to add.
  }
  ScanMetrics scanMetrics = new ScanMetrics();
  if (pScanMetrics != null) {
    for (HBaseProtos.NameInt64Pair pair : pScanMetrics.getMetricsList()) {
      if (pair.hasName() && pair.hasValue()) {
        scanMetrics.setCounter(pair.getName(), pair.getValue());
      }
    }
  }
  return scanMetrics;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:19,代码来源:ProtobufUtil.java

示例3: readProtobuf

import com.google.protobuf.Parser; //导入方法依赖的package包/类
/**
 * De-serializes a protobuf from the given buffer.
 * <p>
 * The protobuf is assumed to be prefixed by a varint indicating its size.
 * @param buf The buffer to de-serialize the protobuf from.
 * @param parser The protobuf parser to use for this type of protobuf.
 * @return An instance of the de-serialized type.
 * @throws InvalidResponseException if the buffer contained an invalid
 * protobuf that couldn't be de-serialized.
 */
static <T> T readProtobuf(final ChannelBuffer buf, final Parser<T> parser) {
  final int length = HBaseRpc.readProtoBufVarint(buf);
  HBaseRpc.checkArrayLength(buf, length);
  final byte[] payload;
  final int offset;
  if (buf.hasArray()) {  // Zero copy.
    payload = buf.array();
    offset = buf.arrayOffset() + buf.readerIndex();
    buf.readerIndex(buf.readerIndex() + length);
  } else {  // We have to copy the entire payload out of the buffer :(
    payload = new byte[length];
    buf.readBytes(payload);
    offset = 0;
  }
  try {
    return parser.parseFrom(payload, offset, length);
  } catch (InvalidProtocolBufferException e) {
    final String msg = "Invalid RPC response: length=" + length
      + ", payload=" + Bytes.pretty(payload);
    LOG.error("Invalid RPC from buffer: " + buf);
    throw new InvalidResponseException(msg, e);
  }
}
 
开发者ID:OpenTSDB,项目名称:asynccassandra,代码行数:34,代码来源:HBaseRpc.java

示例4: parseMessage

import com.google.protobuf.Parser; //导入方法依赖的package包/类
private Message<? extends com.google.protobuf.Message> parseMessage() {
    Envelope envelope = null;

    try {
        envelope = Envelope.parseFrom(record.value());
    } catch (InvalidProtocolBufferException parseError) {
        markAsConsumed(record.offset());
        parsingFailed(envelope, parseError);
        return null;
    }

    try {
        MessageType type = new MessageType(envelope.getMessageType());

        Parser<com.google.protobuf.Message> parser = typeDictionary.parserFor(type);
        if (parser == null) {
            throw new UnknownMessageTypeException(type);
        }

        com.google.protobuf.Message innerMessage = parser.parseFrom(envelope.getInnerMessage());
        return Messages.fromKafka(innerMessage, envelope, record);
    } catch (InvalidProtocolBufferException | UnknownMessageTypeException unrecoverableParsingError) {
        markAsConsumed(record.offset());
        parsingFailed(envelope, unrecoverableParsingError);
        return null;
    }
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:28,代码来源:PartitionProcessor.java

示例5: get

import com.google.protobuf.Parser; //导入方法依赖的package包/类
public static <T> T get(ByteBuf pBody, Parser<T> parser) throws RpcException{
  try {
    ByteBufInputStream is = new ByteBufInputStream(pBody);
    return parser.parseFrom(is);
  } catch (InvalidProtocolBufferException e) {
    throw new RpcException(String.format("Failure while decoding message with parser of type. %s", parser.getClass().getCanonicalName()), e);
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:9,代码来源:RpcBus.java

示例6: read

import com.google.protobuf.Parser; //导入方法依赖的package包/类
public static <Proto> Proto read(byte[] buf, InputStream stream, Parser<Proto> parser)
        throws IOException {
    int leidos = stream.read(buf, 0, 2);
    if (leidos == 2) {
        final int tam = ((buf[0] & 0xff) << 8) | (buf[1] & 0xff);
        leidos = stream.read(buf, 0, tam);
        if (leidos > 0) {
            return parser.parseFrom(buf, 0, leidos);
        }
    }
    return null;
}
 
开发者ID:chochos,项目名称:protobuf-demo,代码行数:13,代码来源:Utils.java

示例7: get

import com.google.protobuf.Parser; //导入方法依赖的package包/类
public static <T> T get(ByteBuf pBody, Parser<T> parser) throws RpcException {
  try {
    ByteBufInputStream is = new ByteBufInputStream(pBody);
    return parser.parseFrom(is);
  } catch (InvalidProtocolBufferException e) {
    throw new RpcException(String.format("Failure while decoding message with parser of type. %s", parser.getClass().getCanonicalName()), e);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:9,代码来源:RpcBus.java

示例8: parseMessage

import com.google.protobuf.Parser; //导入方法依赖的package包/类
private static <T extends Message> T parseMessage(DocumentSnapshot doc, Parser<T> parser) {
    final Blob blob = doc.getBlob(BYTES_KEY);
    final byte[] bytes = blob.toBytes();
    try {
        final T message = parser.parseFrom(bytes);
        return message;
    } catch (InvalidProtocolBufferException e) {
        throw illegalStateWithCauseOf(e);
    }
}
 
开发者ID:SpineEventEngine,项目名称:todo-list,代码行数:11,代码来源:FirebaseSubscriber.java

示例9: parseAny

import com.google.protobuf.Parser; //导入方法依赖的package包/类
private <T> T parseAny(Any value, Parser<T> parser) {
  try {
    return parser.parseFrom(value.getValue());
  } catch (InvalidProtocolBufferException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:googleapis,项目名称:api-compiler,代码行数:8,代码来源:DescriptorGenerator.java

示例10: get

import com.google.protobuf.Parser; //导入方法依赖的package包/类
public static <T> T get(ByteBuf pBody, Parser<T> parser) throws RpcException {
  try {
    ByteBufInputStream is = new ByteBufInputStream(pBody);
    return parser.parseFrom(is);
  } catch (InvalidProtocolBufferException e) {
    throw new RpcException(
        String.format("Failure while decoding message with parser of type. %s",
            parser.getClass().getCanonicalName()), e);
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:11,代码来源:RpcBus.java

示例11: decode

import com.google.protobuf.Parser; //导入方法依赖的package包/类
/**
 * Decode custom protobuf variable length array.
 *
 * @param <T> the item type
 * @param data the raw input, not null
 * @param parser the parser to decode each message, not null
 * @return the decoded list of items, not null
 * @throws IOException
 * @throws NullPointerException if any arguments are null
 */
public static <T> List<T> decode(InputStream data, Parser<T> parser) throws IOException {
    CodedInputStream stream = CodedInputStream.newInstance(data);
    List<T> list = new ArrayList<>();
    while (!stream.isAtEnd()) {
        int size = stream.readRawVarint32();
        byte[] element = stream.readRawBytes(size);
        T decoded = parser.parseFrom(element);
        list.add(decoded);
    }
    return list;
}
 
开发者ID:horrorho,项目名称:LiquidDonkey,代码行数:22,代码来源:ProtoBufArray.java

示例12: readMessage

import com.google.protobuf.Parser; //导入方法依赖的package包/类
public <T extends /*@NonNull*/ AbstractMessage> /*@Nullable*/ T readMessage(long cappedId,
        Parser<T> parser) throws IOException {
    boolean overwritten;
    boolean inTheFuture;
    synchronized (lock) {
        overwritten = out.isOverwritten(cappedId);
        inTheFuture = cappedId >= out.getCurrIndex();
    }
    if (overwritten) {
        return null;
    }
    if (inTheFuture) {
        // this can happen when the glowroot folder is copied for analysis without shutting down
        // the JVM and glowroot.capped.db is copied first, then new data is written to
        // glowroot.capped.db and the new capped ids are written to glowroot.h2.db and then
        // glowroot.h2.db is copied with capped ids that do not exist in the copied
        // glowroot.capped.db
        return null;
    }
    // it's important to wrap CappedBlockInputStream in a BufferedInputStream to prevent
    // lots of small reads from the underlying RandomAccessFile
    final int bufferSize = 32768;
    InputStream input = newLZFInputStream(
            new BufferedInputStream(new CappedBlockInputStream(cappedId), bufferSize));
    try {
        return parser.parseFrom(input);
    } catch (Exception e) {
        if (!out.isOverwritten(cappedId)) {
            logger.error(e.getMessage(), e);
        }
        return null;
    } finally {
        input.close();
    }
}
 
开发者ID:glowroot,项目名称:glowroot,代码行数:36,代码来源:CappedDatabase.java

示例13: getMessage

import com.google.protobuf.Parser; //导入方法依赖的package包/类
public MessageLite getMessage(ProtobaseFuture future) throws InvalidProtocolBufferException {

        Parser<? extends MessageLite> parser = getParser(future.getFutureName());

        return parser.parseFrom(future.getBinary());
    }
 
开发者ID:generallycloud,项目名称:baseio,代码行数:7,代码来源:ProtobufUtil.java


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