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


Java CodedInputStream.getTotalBytesRead方法代码示例

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


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

示例1: skip

import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
@Override
public int skip(PositionedByteRange src) {
  CellProtos.Cell.Builder builder = CellProtos.Cell.newBuilder();
  CodedInputStream is = inputStreamFromByteRange(src);
  is.setSizeLimit(src.getLength());
  try {
    builder.mergeFrom(is);
    int consumed = is.getTotalBytesRead();
    src.setPosition(src.getPosition() + consumed);
    return consumed;
  } catch (IOException e) {
    throw new RuntimeException("Error while skipping type.", e);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:15,代码来源:PBCell.java

示例2: skip

import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
@Override
public int skip(PositionedByteRange src) {
  CellProtos.Cell.Builder builder = CellProtos.Cell.newBuilder();
  CodedInputStream is = inputStreamFromByteRange(src);
  try {
    builder.mergeFrom(is);
    int consumed = is.getTotalBytesRead();
    src.setPosition(src.getPosition() + consumed);
    return consumed;
  } catch (IOException e) {
    throw new RuntimeException("Error while skipping type.", e);
  }
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:14,代码来源:PBCell.java

示例3: 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

示例4: parseRpcRequestFromChannel

import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
public static RpcCall parseRpcRequestFromChannel (AsynchronousSocketChannel channel, BlockingService service) 
  throws InterruptedException, ExecutionException, IOException {
  RpcCall call = null;
    long t = System.currentTimeMillis();
    InputStream in = Channels.newInputStream(channel);
    byte[] datasize = new byte[MESSAGE_LENGHT_FIELD_SIZE];
    in.read(datasize);
    int nDataSize = bytes2Int(datasize);
    
    int len = 0;
    ByteBuffer buf = ByteBuffer.allocateDirect(nDataSize);
    for ( ;len < nDataSize; ) {
      len += channel.read(buf).get();
    }
    if(len < nDataSize) {
      LOG.error("SOCKET READ FAILED, len:" + len);
      return call;
    }
    byte[] data = new byte[nDataSize];
    buf.flip();
    buf.get(data);
    int offset = 0;
    CodedInputStream cis = CodedInputStream.newInstance(data, offset, nDataSize - offset);
    int headerSize =  cis.readRawVarint32();
    offset += cis.getTotalBytesRead();
    RequestHeader header = RequestHeader.newBuilder().mergeFrom(data, offset, headerSize ).build();
    
    offset += headerSize;
    cis.skipRawBytes(headerSize);
    cis.resetSizeCounter();
    int bodySize = cis.readRawVarint32();
    offset += cis.getTotalBytesRead();
    //LOG.debug("header parsed:" + header.toString());
    
    MethodDescriptor md = service.getDescriptorForType().findMethodByName(header.getRequestName());
    Builder builder = service.getRequestPrototype(md).newBuilderForType();
    Message body = null;
    if (builder != null) {
      body = builder.mergeFrom(data, offset, bodySize).build();
      //LOG.debug("server : request parsed:" + body.toString());
    }
    call = new RpcCall(header.getId(), header, body, md);
    if(LOG.isTraceEnabled()) {
      LOG.trace("Parse Rpc request from socket: " + call.getCallId() 
        + ", takes" + (System.currentTimeMillis() -t) + " ms");
    }

  return call;
}
 
开发者ID:chicm,项目名称:CmRaft,代码行数:50,代码来源:PacketUtils.java

示例5: parseRpcResponseFromChannel

import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
public static RpcCall parseRpcResponseFromChannel (AsynchronousSocketChannel channel, BlockingService service) 
  throws InterruptedException, ExecutionException, IOException {
  RpcCall call = null;
    long t = System.currentTimeMillis();
    InputStream in = Channels.newInputStream(channel);
    byte[] datasize = new byte[MESSAGE_LENGHT_FIELD_SIZE];
    in.read(datasize);
    int nDataSize = bytes2Int(datasize);
    
    LOG.debug("message size: " + nDataSize);
    
    int len = 0;
    ByteBuffer buf = ByteBuffer.allocateDirect(nDataSize);
    for ( ;len < nDataSize; ) {
      len += channel.read(buf).get();
    }
    if(len < nDataSize) {
      LOG.error("SOCKET READ FAILED, len:" + len);
      return call;
    }
    byte[] data = new byte[nDataSize];
    buf.flip();
    buf.get(data);
    int offset = 0;
    CodedInputStream cis = CodedInputStream.newInstance(data, offset, nDataSize - offset);
    int headerSize =  cis.readRawVarint32();
    offset += cis.getTotalBytesRead();
    ResponseHeader header = ResponseHeader.newBuilder().mergeFrom(data, offset, headerSize ).build();
    
    offset += headerSize;
    cis.skipRawBytes(headerSize);
    cis.resetSizeCounter();
    int bodySize = cis.readRawVarint32();
    offset += cis.getTotalBytesRead();
    
    MethodDescriptor md = service.getDescriptorForType().findMethodByName(header.getResponseName());
    Builder builder = service.getResponsePrototype(md).newBuilderForType();
    Message body = null;
    if (builder != null) {
      body = builder.mergeFrom(data, offset, bodySize).build();
    }
    call = new RpcCall(header.getId(), header, body, md);
    if(LOG.isTraceEnabled()) {
      LOG.trace("Parse Rpc response from socket: " + call.getCallId() 
        + ", takes" + (System.currentTimeMillis() -t) + " ms");
    }

  return call;
}
 
开发者ID:chicm,项目名称:CmRaft,代码行数:50,代码来源:PacketUtils.java


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