本文整理汇总了Java中com.google.protobuf.CodedInputStream.readRawVarint32方法的典型用法代码示例。如果您正苦于以下问题:Java CodedInputStream.readRawVarint32方法的具体用法?Java CodedInputStream.readRawVarint32怎么用?Java CodedInputStream.readRawVarint32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.CodedInputStream
的用法示例。
在下文中一共展示了CodedInputStream.readRawVarint32方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadINodeSection
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
private static byte[][] loadINodeSection(InputStream in)
throws IOException {
FsImageProto.INodeSection s = FsImageProto.INodeSection
.parseDelimitedFrom(in);
LOG.info("Loading " + s.getNumInodes() + " inodes.");
final byte[][] inodes = new byte[(int) s.getNumInodes()][];
for (int i = 0; i < s.getNumInodes(); ++i) {
int size = CodedInputStream.readRawVarint32(in.read(), in);
byte[] bytes = new byte[size];
IOUtils.readFully(in, bytes, 0, size);
inodes[i] = bytes;
}
LOG.debug("Sorting inodes");
Arrays.sort(inodes, INODE_BYTES_COMPARATOR);
LOG.debug("Finished sorting inodes");
return inodes;
}
示例2: parseField
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
/**
* Parses the field.
*
* @param <T> the generic type
* @param input the input
* @param extensionRegistry the extension registry
* @param type the type
* @param value the value
* @return the t
* @throws IOException Signals that an I/O exception has occurred.
*/
@SuppressWarnings("unchecked")
static <T> T parseField(CodedInputStream input, ExtensionRegistryLite extensionRegistry, WireFormat.FieldType type,
T value) throws IOException {
switch (type) {
case MESSAGE:
int length = input.readRawVarint32();
final int oldLimit = input.pushLimit(length);
Codec<? extends Object> codec = ProtobufProxy.create(value.getClass());
T ret = (T) codec.decode(input.readRawBytes(length));
input.popLimit(oldLimit);
return ret;
case ENUM:
return (T) (java.lang.Integer) input.readEnum();
case GROUP:
throw new RuntimeException("Groups are not allowed in maps.");
default:
return (T) CodedConstant.readPrimitiveField(input, type, true);
}
}
示例3: readPreprocessedBlock
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
private Iterable<RtbImpression> readPreprocessedBlock(BlockContext context) throws IOException {
List<RtbImpression> impressions = new ArrayList<>();
try (InputStream is = context.createInputStream(PREPROCESS)) {
CodedInputStream cis = CodedInputStream.newInstance(is);
while (!cis.isAtEnd()) {
int len = cis.readRawVarint32();
int oldLimit = cis.pushLimit(len);
impressions.add(RtbImpression.parseFrom(cis));
cis.popLimit(oldLimit);
}
}
return impressions;
}
示例4: 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);
}
}
示例5: apply
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
List<T> apply(InputStream in) throws IOException {
List<T> list = new ArrayList<>();
CodedInputStream stream = CodedInputStream.newInstance(in);
int size;
while (!stream.isAtEnd() && (size = stream.readRawVarint32()) != 0) {
ByteArrayInputStream delimited = new ByteArrayInputStream(stream.readRawBytes(size));
list.add(parse.apply(delimited));
}
return list;
}
示例6: decode
import com.google.protobuf.CodedInputStream; //导入方法依赖的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;
}
示例7: readPBData
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
public static Data readPBData(InputStream input) throws Exception {
int firstByte = input.read();
if (firstByte == -1) {
throw new Exception("Improper Request format! Reached EOF prematurely!");
}
int size = CodedInputStream.readRawVarint32(firstByte, input);
byte[] bytes = new byte[size];
readFully(input,bytes,size);
return new PBDataImpl(bytes);
}
示例8: onSendTables
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
@OnMessage(Demo.CDemoSendTables.class)
public void onSendTables(Context ctx, Demo.CDemoSendTables message) throws IOException {
CodedInputStream cis = CodedInputStream.newInstance(ZeroCopy.extract(message.getData()));
int size = cis.readRawVarint32();
S2NetMessages.CSVCMsg_FlattenedSerializer fs = Packet.parse(S2NetMessages.CSVCMsg_FlattenedSerializer.class, ZeroCopy.wrap(cis.readRawBytes(size)));
Set<String> baseTypes = new TreeSet<>();
for (S2NetMessages.ProtoFlattenedSerializer_t s : fs.getSerializersList()) {
for (int fi : s.getFieldsIndexList()) {
S2NetMessages.ProtoFlattenedSerializerField_t f = fs.getFields(fi);
FieldType ft = new FieldType(fs.getSymbols(f.getVarTypeSym()));
if (!f.hasFieldSerializerNameSym()) {
int l = 0;
do {
baseTypes.add(ft.getBaseType().toUpperCase());
if ("CUTLVECTOR".equals(ft.getBaseType().toUpperCase())) {
ft = ft.getGenericType();
} else {
ft = null;
}
l++;
} while (l <= 1 && ft != null);
}
}
}
dump(ctx, fs);
}
示例9: 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);
}
示例10: 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;
}
示例11: 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;
}
示例12: 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;
}