本文整理汇总了Java中com.google.protobuf.CodedInputStream.readTag方法的典型用法代码示例。如果您正苦于以下问题:Java CodedInputStream.readTag方法的具体用法?Java CodedInputStream.readTag怎么用?Java CodedInputStream.readTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.CodedInputStream
的用法示例。
在下文中一共展示了CodedInputStream.readTag方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readFrom
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
public static BlockListAsLongs readFrom(InputStream is) throws IOException {
CodedInputStream cis = CodedInputStream.newInstance(is);
int numBlocks = -1;
ByteString blocksBuf = null;
while (!cis.isAtEnd()) {
int tag = cis.readTag();
int field = WireFormat.getTagFieldNumber(tag);
switch(field) {
case 0:
break;
case 1:
numBlocks = (int)cis.readInt32();
break;
case 2:
blocksBuf = cis.readBytes();
break;
default:
cis.skipField(tag);
break;
}
}
if (numBlocks != -1 && blocksBuf != null) {
return decodeBuffer(numBlocks, blocksBuf);
}
return null;
}
示例2: parseEntry
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
/**
* Parses the entry.
*
* @param <K> the key type
* @param <V> the value type
* @param input the input
* @param metadata the metadata
* @param extensionRegistry the extension registry
* @return the map. entry
* @throws IOException Signals that an I/O exception has occurred.
*/
static <K, V> Map.Entry<K, V> parseEntry(CodedInputStream input, Metadata<K, V> metadata,
ExtensionRegistryLite extensionRegistry) throws IOException {
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;
}
}
}
return new AbstractMap.SimpleImmutableEntry<K, V>(key, value);
}
示例3: isWallet
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
/**
* Cheap test to see if input stream is a wallet. This checks for a magic value at the beginning of the stream.
*
* @param is
* input stream to test
* @return true if input stream is a wallet
*/
public static boolean isWallet(InputStream is) {
try {
final CodedInputStream cis = CodedInputStream.newInstance(is);
final int tag = cis.readTag();
final int field = WireFormat.getTagFieldNumber(tag);
if (field != 1) // network_identifier
return false;
final String network = cis.readString();
return NetworkParameters.fromID(network) != null;
} catch (IOException x) {
return false;
}
}
示例4: isWallet
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
/**
* Cheap test to see if input stream is a wallet. This checks for a magic value at the beginning of the stream.
*
* @param is
* input stream to test
* @return true if input stream is a wallet
*/
public static boolean isWallet(InputStream is) {
try {
final CodedInputStream cis = CodedInputStream.newInstance(is);
final int tag = cis.readTag();
final int field = WireFormat.getTagFieldNumber(tag);
if (field != 1) // network_identifier
return false;
final String network = cis.readString();
return NetworkParameters.fromID(network) != null;
} catch (IOException x) {
return false;
}
}
示例5: SyncMessageContext
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
private SyncMessageContext(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
this.memoizedIsInitialized = -1;
this.memoizedSerializedSize = -1;
this.initFields();
boolean mutable_bitField0_ = false;
com.google.protobuf.UnknownFieldSet.Builder unknownFields = UnknownFieldSet.newBuilder();
try {
boolean e = false;
while(!e) {
int tag = input.readTag();
switch(tag) {
case 0:
e = true;
break;
case 10:
this.bitField0_ |= 1;
this.destination_ = input.readBytes();
break;
case 16:
this.bitField0_ |= 2;
this.timestamp_ = input.readUInt64();
break;
default:
if(!this.parseUnknownField(input, unknownFields, extensionRegistry, tag)) {
e = true;
}
}
}
} catch (InvalidProtocolBufferException var11) {
throw var11.setUnfinishedMessage(this);
} catch (IOException var12) {
throw (new InvalidProtocolBufferException(var12.getMessage())).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
this.makeExtensionsImmutable();
}
}
示例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: extractTimestampMillis
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
public long extractTimestampMillis(String topic, final byte[] bytes) throws IOException {
if (timestampFieldPath != null) {
com.google.protobuf.Message decodedMessage = protobufUtil.decodeProtobufOrJsonMessage(topic,
bytes);
int i = 0;
for (; i < timestampFieldPath.length - 1; ++i) {
decodedMessage = (com.google.protobuf.Message) decodedMessage
.getField(decodedMessage.getDescriptorForType().findFieldByName(timestampFieldPath[i]));
}
Object timestampObject = decodedMessage
.getField(decodedMessage.getDescriptorForType().findFieldByName(timestampFieldPath[i]));
if (timestampObject instanceof com.google.protobuf.Timestamp){
return Timestamps.toMillis((com.google.protobuf.Timestamp) timestampObject);
}else {
return toMillis((Long) timestampObject);
}
} else {
// Assume that the timestamp field is the first field, is required,
// and is a uint64.
CodedInputStream input = CodedInputStream.newInstance(bytes);
// Don't really care about the tag, but need to read it to get, to
// the payload.
input.readTag();
return toMillis(input.readUInt64());
}
}
示例8: PushSMPMessageContent
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
private PushSMPMessageContent(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
this.memoizedIsInitialized = -1;
this.memoizedSerializedSize = -1;
this.initFields();
int mutable_bitField0_ = 0;
com.google.protobuf.UnknownFieldSet.Builder unknownFields = UnknownFieldSet.newBuilder();
try {
boolean e = false;
while(!e) {
int tag = input.readTag();
switch(tag) {
case 0:
e = true;
break;
case 10:
this.bitField0_ |= 1;
this.body_ = input.readBytes();
break;
case 18:
if((mutable_bitField0_ & 2) != 2) {
this.attachments_ = new ArrayList();
mutable_bitField0_ |= 2;
}
this.attachments_.add(input.readMessage(PushSMPMessageProtos.PushSMPMessageContent.AttachmentPointer.PARSER, extensionRegistry));
break;
case 26:
PushSMPMessageProtos.PushSMPMessageContent.GroupContext.Builder subBuilder1 = null;
if((this.bitField0_ & 2) == 2) {
subBuilder1 = this.group_.toBuilder();
}
this.group_ = (PushSMPMessageProtos.PushSMPMessageContent.GroupContext)input.readMessage(PushSMPMessageProtos.PushSMPMessageContent.GroupContext.PARSER, extensionRegistry);
if(subBuilder1 != null) {
subBuilder1.mergeFrom(this.group_);
this.group_ = subBuilder1.buildPartial();
}
this.bitField0_ |= 2;
break;
case 32:
this.bitField0_ |= 4;
this.flags_ = input.readUInt32();
break;
case 42:
PushSMPMessageProtos.PushSMPMessageContent.SyncMessageContext.Builder subBuilder = null;
if((this.bitField0_ & 8) == 8) {
subBuilder = this.sync_.toBuilder();
}
this.sync_ = (PushSMPMessageProtos.PushSMPMessageContent.SyncMessageContext)input.readMessage(PushSMPMessageProtos.PushSMPMessageContent.SyncMessageContext.PARSER, extensionRegistry);
if(subBuilder != null) {
subBuilder.mergeFrom(this.sync_);
this.sync_ = subBuilder.buildPartial();
}
this.bitField0_ |= 8;
break;
default:
if(!this.parseUnknownField(input, unknownFields, extensionRegistry, tag)) {
e = true;
}
}
}
} catch (InvalidProtocolBufferException var12) {
throw var12.setUnfinishedMessage(this);
} catch (IOException var13) {
throw (new InvalidProtocolBufferException(var13.getMessage())).setUnfinishedMessage(this);
} finally {
if((mutable_bitField0_ & 2) == 2) {
this.attachments_ = Collections.unmodifiableList(this.attachments_);
}
this.unknownFields = unknownFields.build();
this.makeExtensionsImmutable();
}
}
示例9: GroupContext
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
private GroupContext(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
this.memoizedIsInitialized = -1;
this.memoizedSerializedSize = -1;
this.initFields();
int mutable_bitField0_ = 0;
com.google.protobuf.UnknownFieldSet.Builder unknownFields = UnknownFieldSet.newBuilder();
try {
boolean e = false;
while(!e) {
int tag = input.readTag();
switch(tag) {
case 0:
e = true;
break;
case 10:
this.bitField0_ |= 1;
this.id_ = input.readBytes();
break;
case 16:
int subBuilder1 = input.readEnum();
PushSMPMessageProtos.PushSMPMessageContent.GroupContext.Type value = PushSMPMessageProtos.PushSMPMessageContent.GroupContext.Type.valueOf(subBuilder1);
if(value == null) {
unknownFields.mergeVarintField(2, subBuilder1);
} else {
this.bitField0_ |= 2;
this.type_ = value;
}
break;
case 26:
this.bitField0_ |= 4;
this.name_ = input.readBytes();
break;
case 34:
if((mutable_bitField0_ & 8) != 8) {
this.members_ = new LazyStringArrayList();
mutable_bitField0_ |= 8;
}
this.members_.add(input.readBytes());
break;
case 42:
PushSMPMessageProtos.PushSMPMessageContent.AttachmentPointer.Builder subBuilder = null;
if((this.bitField0_ & 8) == 8) {
subBuilder = this.avatar_.toBuilder();
}
this.avatar_ = (PushSMPMessageProtos.PushSMPMessageContent.AttachmentPointer)input.readMessage(PushSMPMessageProtos.PushSMPMessageContent.AttachmentPointer.PARSER, extensionRegistry);
if(subBuilder != null) {
subBuilder.mergeFrom(this.avatar_);
this.avatar_ = subBuilder.buildPartial();
}
this.bitField0_ |= 8;
break;
default:
if(!this.parseUnknownField(input, unknownFields, extensionRegistry, tag)) {
e = true;
}
}
}
} catch (InvalidProtocolBufferException var13) {
throw var13.setUnfinishedMessage(this);
} catch (IOException var14) {
throw (new InvalidProtocolBufferException(var14.getMessage())).setUnfinishedMessage(this);
} finally {
if((mutable_bitField0_ & 8) == 8) {
this.members_ = new UnmodifiableLazyStringList(this.members_);
}
this.unknownFields = unknownFields.build();
this.makeExtensionsImmutable();
}
}
示例10: AttachmentPointer
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
private AttachmentPointer(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
this.memoizedIsInitialized = -1;
this.memoizedSerializedSize = -1;
this.initFields();
boolean mutable_bitField0_ = false;
com.google.protobuf.UnknownFieldSet.Builder unknownFields = UnknownFieldSet.newBuilder();
try {
boolean e = false;
while(!e) {
int tag = input.readTag();
switch(tag) {
case 0:
e = true;
break;
case 9:
this.bitField0_ |= 1;
this.id_ = input.readFixed64();
break;
case 18:
this.bitField0_ |= 2;
this.contentType_ = input.readBytes();
break;
case 26:
this.bitField0_ |= 4;
this.key_ = input.readBytes();
break;
default:
if(!this.parseUnknownField(input, unknownFields, extensionRegistry, tag)) {
e = true;
}
}
}
} catch (InvalidProtocolBufferException var11) {
throw var11.setUnfinishedMessage(this);
} catch (IOException var12) {
throw (new InvalidProtocolBufferException(var12.getMessage())).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
this.makeExtensionsImmutable();
}
}
示例11: IncomingPushMessageSignal
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
private IncomingPushMessageSignal(CodedInputStream input, ExtensionRegistryLite extensionRegistry) throws InvalidProtocolBufferException {
this.memoizedIsInitialized = -1;
this.memoizedSerializedSize = -1;
this.initFields();
boolean mutable_bitField0_ = false;
com.google.protobuf.UnknownFieldSet.Builder unknownFields = UnknownFieldSet.newBuilder();
try {
boolean e = false;
while(!e) {
int tag = input.readTag();
switch(tag) {
case 0:
e = true;
break;
case 8:
int rawValue = input.readEnum();
PushSMPMessageProtos.IncomingPushMessageSignal.Type value = PushSMPMessageProtos.IncomingPushMessageSignal.Type.valueOf(rawValue);
if(value == null) {
unknownFields.mergeVarintField(1, rawValue);
} else {
this.bitField0_ |= 1;
this.type_ = value;
}
break;
case 18:
this.bitField0_ |= 2;
this.source_ = input.readBytes();
break;
case 26:
this.bitField0_ |= 8;
this.relay_ = input.readBytes();
break;
case 40:
this.bitField0_ |= 16;
this.timestamp_ = input.readUInt64();
break;
case 50:
this.bitField0_ |= 32;
this.message_ = input.readBytes();
break;
case 56:
this.bitField0_ |= 4;
this.sourceDevice_ = input.readUInt32();
break;
default:
if(!this.parseUnknownField(input, unknownFields, extensionRegistry, tag)) {
e = true;
}
}
}
} catch (InvalidProtocolBufferException var13) {
throw var13.setUnfinishedMessage(this);
} catch (IOException var14) {
throw (new InvalidProtocolBufferException(var14.getMessage())).setUnfinishedMessage(this);
} finally {
this.unknownFields = unknownFields.build();
this.makeExtensionsImmutable();
}
}
示例12: 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;
}
示例13: readPoint
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
private void readPoint(Track track, CodedInputStream input) throws IOException {
int latitudeE6 = 0;
int longitudeE6 = 0;
boolean continuous = true;
float altitude = Float.NaN;
float speed = Float.NaN;
float bearing = Float.NaN;
float accuracy = Float.NaN;
long timestamp = 0L;
boolean done = false;
while (!done) {
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_POINT_LATITUDE: {
latitudeE6 = input.readInt32();
break;
}
case FIELD_POINT_LONGITUDE: {
longitudeE6 = input.readInt32();
break;
}
case FIELD_POINT_ALTITUDE: {
altitude = input.readFloat();
break;
}
case FIELD_POINT_SPEED: {
speed = input.readFloat();
break;
}
case FIELD_POINT_BEARING: {
bearing = input.readFloat();
break;
}
case FIELD_POINT_ACCURACY: {
accuracy = input.readFloat();
break;
}
case FIELD_POINT_TIMESTAMP: {
timestamp = input.readUInt64();
break;
}
case FIELD_POINT_CONTINUOUS: {
continuous = input.readBool();
break;
}
}
}
track.addPointFast(continuous, latitudeE6, longitudeE6, altitude, speed, bearing, accuracy, timestamp);
}