本文整理汇总了Java中com.google.protobuf.CodedInputStream.readInt32方法的典型用法代码示例。如果您正苦于以下问题:Java CodedInputStream.readInt32方法的具体用法?Java CodedInputStream.readInt32怎么用?Java CodedInputStream.readInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.protobuf.CodedInputStream
的用法示例。
在下文中一共展示了CodedInputStream.readInt32方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: deserialize
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
@Override
public NestedSet<T> deserialize(CodedInputStream codedIn)
throws SerializationException, IOException {
Map<ByteString, Object> digestToChild = new HashMap<>();
int nestedSetCount = codedIn.readInt32();
Preconditions.checkState(
nestedSetCount >= 1,
"Should have at least serialized one nested set, got: %d",
nestedSetCount);
Order order = orderCodec.deserialize(codedIn);
Object children = null;
for (int i = 0; i < nestedSetCount; ++i) {
// Update var, the last one in the list is the top level nested set
children = deserializeOneNestedSet(codedIn, digestToChild);
}
return createNestedSet(order, children);
}
示例3: deserializeOneNestedSet
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
private Object deserializeOneNestedSet(
CodedInputStream codedIn, Map<ByteString, Object> digestToChild)
throws SerializationException, IOException {
ByteString digest = codedIn.readBytes();
CodedInputStream childCodedIn = codedIn.readBytes().newCodedInput();
childCodedIn.enableAliasing(true); // Allow efficient views of byte slices when reading digests
int childCount = childCodedIn.readInt32();
final Object result;
if (childCount > 1) {
result = deserializeMultipleItemChildArray(digestToChild, childCodedIn, childCount);
} else if (childCount == 1) {
result = objectCodec.deserialize(childCodedIn);
} else {
result = NestedSet.EMPTY_CHILDREN;
}
digestToChild.put(digest, result);
return result;
}
示例4: deserialize
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked") // Class<? extends...> cast
public Key deserialize(CodedInputStream codedIn) throws SerializationException, IOException {
BuildOptions buildOptions = BuildOptions.CODEC.deserialize(codedIn);
int fragmentsSize = codedIn.readInt32();
ImmutableSortedSet.Builder<Class<? extends BuildConfiguration.Fragment>> fragmentsBuilder =
ImmutableSortedSet.orderedBy(BuildConfiguration.lexicalFragmentSorter);
for (int i = 0; i < fragmentsSize; i++) {
try {
fragmentsBuilder.add(
(Class<? extends BuildConfiguration.Fragment>)
Class.forName(StringCodecs.asciiOptimized().deserialize(codedIn)));
} catch (ClassNotFoundException e) {
throw new SerializationException(
"Couldn't deserialize BuildConfigurationValue$Key fragment class", e);
}
}
return key(fragmentsBuilder.build(), buildOptions);
}
示例5: 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;
}
示例6: 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;
}
示例7: deserialize
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
@Override
public PathFragment deserialize(CodedInputStream codedIn)
throws IOException, SerializationException {
char driveLetter = (char) codedIn.readInt32();
boolean isAbsolute = codedIn.readBool();
int segmentCount = codedIn.readInt32();
String[] segments = new String[segmentCount];
for (int i = 0; i < segmentCount; i++) {
segments[i] = stringCodec.deserialize(codedIn);
}
return PathFragment.create(driveLetter, isAbsolute, segments);
}
示例8: deserialize
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
@Override
public ImmutableList<T> deserialize(CodedInputStream codedIn)
throws SerializationException, IOException {
int length = codedIn.readInt32();
if (length < 0) {
throw new SerializationException("Expected non-negative length: " + length);
}
ImmutableList.Builder<T> builder = ImmutableList.builder();
for (int i = 0; i < length; i++) {
builder.add(codec.deserialize(codedIn));
}
return builder.build();
}
示例9: deserialize
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
@Override
public String deserialize(CodedInputStream codedIn) throws IOException {
int length = codedIn.readInt32();
if (length == 0) {
return EMPTY_STRING;
}
char[] maybeDecoded = new char[length];
for (int i = 0; i < length; i++) {
// Read one byte at a time to avoid creating a new ByteString/copy of the underlying array.
byte b = codedIn.readRawByte();
// Check highest order bit, if it's set we've crossed into extended ascii/utf8.
if ((b & 0x80) == 0) {
maybeDecoded[i] = (char) b;
} else {
// Fail, we encountered a non-ascii byte. Copy what we have so far plus and then the rest
// of the data into a buffer and let String's constructor do the UTF-8 decoding work.
byte[] decodeFrom = new byte[length];
for (int j = 0; j < i; j++) {
decodeFrom[j] = (byte) maybeDecoded[j];
}
decodeFrom[i] = b;
for (int j = i + 1; j < length; j++) {
decodeFrom[j] = codedIn.readRawByte();
}
return new String(decodeFrom, StandardCharsets.UTF_8);
}
}
try {
String result = (String) theUnsafe.allocateInstance(String.class);
theUnsafe.putObject(result, STRING_VALUE_OFFSET, maybeDecoded);
return result;
} catch (Exception e) {
// This should only catch InstantiationException, but that makes IntelliJ unhappy for
// some reason; it insists that that exception cannot be thrown from here, even though it
// is set to JDK 8
throw new IllegalStateException("Could not create string", e);
}
}
示例10: deserialize
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
@Override
public DottedVersion deserialize(CodedInputStream codedIn) throws IOException {
int numComponents = codedIn.readInt32();
// TODO(janakr: Presize this if/when https://github.com/google/guava/issues/196 is
// resolved.
ImmutableList.Builder<Component> components = ImmutableList.builder();
for (int i = 0; i < numComponents; i++) {
components.add(Component.deserialize(codedIn));
}
return new DottedVersion(components.build(), codedIn.readString(), codedIn.readInt32());
}
示例11: deserialize
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
@Override
public BuildConfiguration deserialize(FileSystemProvider fsProvider, CodedInputStream codedIn)
throws SerializationException, IOException {
BlazeDirectories blazeDirectories = BlazeDirectories.CODEC.deserialize(fsProvider, codedIn);
int length = codedIn.readInt32();
ImmutableSortedMap.Builder<Class<? extends Fragment>, Fragment> builder =
new ImmutableSortedMap.Builder<>(lexicalFragmentSorter);
for (int i = 0; i < length; ++i) {
Fragment fragment = Fragment.CODEC.deserialize(fsProvider, codedIn);
builder.put(fragment.getClass(), fragment);
}
BuildOptions options = BuildOptions.CODEC.deserialize(codedIn);
String repositoryName = StringCodecs.asciiOptimized().deserialize(codedIn);
return new BuildConfiguration(blazeDirectories, builder.build(), options, repositoryName);
}
示例12: deserialize
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
@Override
public BuildOptions deserialize(CodedInputStream codedIn)
throws IOException, SerializationException {
BuildOptions.Builder builder = BuildOptions.builder();
int length = codedIn.readInt32();
for (int i = 0; i < length; ++i) {
builder.add(FragmentOptions.CODEC.deserialize(codedIn));
}
return builder.build();
}
示例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);
}
示例14: readPrimitiveField
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
/**
* Read a field of any primitive type for immutable messages from a CodedInputStream. Enums, groups, and embedded
* messages are not handled by this method.
*
* @param input The stream from which to read.
* @param type Declared type of the field.
* @param checkUtf8 When true, check that the input is valid utf8.
* @return An object representing the field's value, of the exact type which would be returned by
* {@link Message#getField(Descriptors.FieldDescriptor)} for this field.
* @throws IOException Signals that an I/O exception has occurred.
*/
public static Object readPrimitiveField(CodedInputStream input, final WireFormat.FieldType type, boolean checkUtf8)
throws IOException {
switch (type) {
case DOUBLE:
return input.readDouble();
case FLOAT:
return input.readFloat();
case INT64:
return input.readInt64();
case UINT64:
return input.readUInt64();
case INT32:
return input.readInt32();
case FIXED64:
return input.readFixed64();
case FIXED32:
return input.readFixed32();
case BOOL:
return input.readBool();
case STRING:
if (checkUtf8) {
return input.readStringRequireUtf8();
} else {
return input.readString();
}
case BYTES:
return input.readBytes();
case UINT32:
return input.readUInt32();
case SFIXED32:
return input.readSFixed32();
case SFIXED64:
return input.readSFixed64();
case SINT32:
return input.readSInt32();
case SINT64:
return input.readSInt64();
case GROUP:
throw new IllegalArgumentException("readPrimitiveField() cannot handle nested groups.");
case MESSAGE:
throw new IllegalArgumentException("readPrimitiveField() cannot handle embedded messages.");
case ENUM:
// We don't handle enums because we don't know what to do if the
// value is not recognized.
throw new IllegalArgumentException("readPrimitiveField() cannot handle enums.");
}
throw new RuntimeException("There is no way to get here, but the compiler thinks otherwise.");
}
示例15: deserialize
import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
@Override
public Integer deserialize(CodedInputStream codedIn)
throws SerializationException, IOException {
return codedIn.readInt32();
}