當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。