当前位置: 首页>>代码示例>>Java>>正文


Java CodedInputStream.readString方法代码示例

本文整理汇总了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;
    }
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:21,代码来源:WalletProtobufSerializer.java

示例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;
    }
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:21,代码来源:WalletProtobufSerializer.java

示例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());
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:12,代码来源:DottedVersion.java

示例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.");
}
 
开发者ID:jhunters,项目名称:jprotobuf,代码行数:62,代码来源:CodedConstant.java

示例5: deserialize

import com.google.protobuf.CodedInputStream; //导入方法依赖的package包/类
@Override
public String deserialize(CodedInputStream codedIn) throws IOException {
  return codedIn.readString();
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:5,代码来源:StringCodec.java


注:本文中的com.google.protobuf.CodedInputStream.readString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。