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


Java CodedInputStream.checkLastTagWas方法代码示例

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


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

示例1: readFrom

import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
<T> T readFrom(ByteBuffer bb) throws IOException {
  // using the parser with a byte[]-backed coded input stream is the
  // most efficient way to deserialize a protobuf.  it has a direct
  // path to the PB ctor that doesn't create multi-layered streams
  // that internally buffer.
  CodedInputStream cis = CodedInputStream.newInstance(
      bb.array(), bb.position() + bb.arrayOffset(), bb.remaining());
  try {
    cis.pushLimit(cis.readRawVarint32());
    message = message.getParserForType().parseFrom(cis);
    cis.checkLastTagWas(0);
  } finally {
    // advance over the bytes read.
    bb.position(bb.position() + cis.getTotalBytesRead());
  }
  return (T)message;
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:20,代码来源:RpcWritable.java

示例2: mergeDelimitedFrom

import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
/**
 * This version of protobuf's mergeDelimitedFrom avoids the hard-coded 64MB limit for decoding
 * buffers
 * @param builder current message builder
 * @param in Inputsream with delimited protobuf data
 * @throws IOException
 */
public static void mergeDelimitedFrom(Message.Builder builder, InputStream in)
  throws IOException {
  // This used to be builder.mergeDelimitedFrom(in);
  // but is replaced to allow us to bump the protobuf size limit.
  final int firstByte = in.read();
  if (firstByte != -1) {
    final int size = CodedInputStream.readRawVarint32(firstByte, in);
    final InputStream limitedInput = new LimitInputStream(in, size);
    final CodedInputStream codedInput = CodedInputStream.newInstance(limitedInput);
    codedInput.setSizeLimit(size);
    builder.mergeFrom(codedInput);
    codedInput.checkLastTagWas(0);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:22,代码来源:ProtobufUtil.java

示例3: mergeFrom

import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
/**
 * This version of protobuf's mergeFrom avoids the hard-coded 64MB limit for decoding
 * buffers where the message size is not known
 * @param builder current message builder
 * @param in InputStream containing protobuf data
 * @throws IOException 
 */
public static void mergeFrom(Message.Builder builder, InputStream in)
    throws IOException {
  final CodedInputStream codedInput = CodedInputStream.newInstance(in);
  codedInput.setSizeLimit(Integer.MAX_VALUE);
  builder.mergeFrom(codedInput);
  codedInput.checkLastTagWas(0);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:15,代码来源:ProtobufUtil.java

示例4: parseInto

import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
/**
 * Parses an entry off of the input into the map. This helper avoids allocaton of a {@link MapEntryLite} by parsing
 * directly into the provided {@link MapFieldLite}.
 *
 * @param map the map
 * @param input the input
 * @param extensionRegistry the extension registry
 * @throws IOException Signals that an I/O exception has occurred.
 */
public void parseInto(MapFieldLite<K, V> map, CodedInputStream input, ExtensionRegistryLite extensionRegistry)
        throws IOException {
    int length = input.readRawVarint32();
    final int oldLimit = input.pushLimit(length);
    K key = metadata.defaultKey;
    V value = metadata.defaultValue;

    while (true) {
        int tag = input.readTag();
        if (tag == 0) {
            break;
        }
        if (tag == CodedConstant.makeTag(KEY_FIELD_NUMBER, metadata.keyType.getWireType())) {
            key = parseField(input, extensionRegistry, metadata.keyType, key);
        } else if (tag == CodedConstant.makeTag(VALUE_FIELD_NUMBER, metadata.valueType.getWireType())) {
            value = parseField(input, extensionRegistry, metadata.valueType, value);
        } else {
            if (!input.skipField(tag)) {
                break;
            }
        }
    }

    input.checkLastTagWas(0);
    input.popLimit(oldLimit);
    map.put(key, value);
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:37,代码来源:MapEntryLite.java

示例5: loadData

import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
@NonNull
@Override
public FileDataSource loadData(InputStream inputStream, String filePath) throws Exception {
    long propertiesOffset = 0L;
    Track track = new Track();
    CodedInputStream input = CodedInputStream.newInstance(inputStream);
    boolean done = false;
    while (!done) {
        long offset = input.getTotalBytesRead();
        int tag = input.readTag();
        int field = WireFormat.getTagFieldNumber(tag);
        switch (field) {
            case 0:
                done = true;
                break;
            default: {
                throw new com.google.protobuf.InvalidProtocolBufferException("Unsupported proto field: " + tag);
            }
            case FIELD_VERSION: {
                // skip version
                input.skipField(tag);
                break;
            }
            case FIELD_POINT: {
                int length = input.readRawVarint32();
                int oldLimit = input.pushLimit(length);
                readPoint(track, input);
                input.popLimit(oldLimit);
                input.checkLastTagWas(0);
                break;
            }
            case FIELD_NAME: {
                propertiesOffset = offset;
                track.name = input.readBytes().toStringUtf8();
                break;
            }
            case FIELD_COLOR: {
                track.style.color = input.readUInt32();
                break;
            }
            case FIELD_WIDTH: {
                track.style.width = input.readFloat();
                break;
            }
        }
    }
    inputStream.close();
    track.id = 31 * filePath.hashCode() + 1;
    FileDataSource dataSource = new FileDataSource();
    dataSource.name = track.name;
    dataSource.tracks.add(track);
    track.source = dataSource;
    dataSource.propertiesOffset = propertiesOffset;
    return dataSource;
}
 
开发者ID:andreynovikov,项目名称:trekarta,代码行数:56,代码来源:TrackManager.java

示例6: mergeFrom

import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
/**
 * This version of protobuf's mergeFrom avoids the hard-coded 64MB limit for decoding
 * buffers when working with byte arrays
 * @param builder current message builder
 * @param b byte array
 * @throws IOException
 */
public static void mergeFrom(Message.Builder builder, byte[] b) throws IOException {
  final CodedInputStream codedInput = CodedInputStream.newInstance(b);
  codedInput.setSizeLimit(b.length);
  builder.mergeFrom(codedInput);
  codedInput.checkLastTagWas(0);
}
 
开发者ID:apache,项目名称:hbase,代码行数:14,代码来源:ProtobufUtil.java


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