本文整理匯總了Java中com.google.protobuf.CodedInputStream.readString方法的典型用法代碼示例。如果您正苦於以下問題:Java CodedInputStream.readString方法的具體用法?Java CodedInputStream.readString怎麽用?Java CodedInputStream.readString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.protobuf.CodedInputStream
的用法示例。
在下文中一共展示了CodedInputStream.readString方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
}
示例2: 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;
}
}
示例3: 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());
}
示例4: 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.");
}
示例5: deserialize
import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
@Override
public String deserialize(CodedInputStream codedIn) throws IOException {
return codedIn.readString();
}