本文整理汇总了Java中com.google.protobuf.CodedInputStream.pushLimit方法的典型用法代码示例。如果您正苦于以下问题:Java CodedInputStream.pushLimit方法的具体用法?Java CodedInputStream.pushLimit怎么用?Java CodedInputStream.pushLimit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.CodedInputStream
的用法示例。
在下文中一共展示了CodedInputStream.pushLimit方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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: readLog
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
private OnlineSectioningLog.ExportedLog readLog(CodedInputStream cin) throws IOException {
if (cin.isAtEnd()) return null;
int size = cin.readInt32();
int limit = cin.pushLimit(size);
OnlineSectioningLog.ExportedLog ret = OnlineSectioningLog.ExportedLog.parseFrom(cin);
cin.popLimit(limit);
cin.resetSizeCounter();
return ret;
}
示例5: readTable
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
public static TableData.Table readTable(CodedInputStream cin) throws IOException {
if (cin.isAtEnd()) return null;
int size = cin.readInt32();
int limit = cin.pushLimit(size);
TableData.Table ret = TableData.Table.parseFrom(cin);
cin.popLimit(limit);
cin.resetSizeCounter();
return ret;
}
示例6: 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);
}
示例7: 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;
}