本文整理汇总了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);
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}