本文整理汇总了Java中com.google.protobuf.WireFormat.getTagFieldNumber方法的典型用法代码示例。如果您正苦于以下问题:Java WireFormat.getTagFieldNumber方法的具体用法?Java WireFormat.getTagFieldNumber怎么用?Java WireFormat.getTagFieldNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.WireFormat
的用法示例。
在下文中一共展示了WireFormat.getTagFieldNumber方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readFrom
import com.google.protobuf.WireFormat; //导入方法依赖的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: isWallet
import com.google.protobuf.WireFormat; //导入方法依赖的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;
}
}
示例3: readTag
import com.google.protobuf.WireFormat; //导入方法依赖的package包/类
public int readTag() throws IOException {
if (isAtEnd()) {
lastTag = 0;
return 0;
}
lastTag = readRawVarint32();
if (WireFormat.getTagFieldNumber(lastTag) == 0) {
// If we actually read zero (or any tag number corresponding to field
// number zero), that's not a valid tag.
throw new InvalidProtocolBufferException("CodedInputStream encountered a malformed varint.");
}
return lastTag;
}
示例4: isWallet
import com.google.protobuf.WireFormat; //导入方法依赖的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: loadData
import com.google.protobuf.WireFormat; //导入方法依赖的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;
}
示例6: readPoint
import com.google.protobuf.WireFormat; //导入方法依赖的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);
}