當前位置: 首頁>>代碼示例>>Java>>正文


Java CodedInputStream.readInt32方法代碼示例

本文整理匯總了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;
}
 
開發者ID:aliyun-beta,項目名稱:aliyun-oss-hadoop-fs,代碼行數:27,代碼來源:BlockListAsLongs.java

示例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);
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:18,代碼來源:NestedSetCodec.java

示例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;
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:19,代碼來源:NestedSetCodec.java

示例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);
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:20,代碼來源:BuildConfigurationValue.java

示例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;
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:10,代碼來源:ReplayLogTest.java

示例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;
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:10,代碼來源:SessionRestore.java

示例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);
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:13,代碼來源:PathFragment.java

示例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();
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:15,代碼來源:ImmutableListCodec.java

示例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);
  }
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:41,代碼來源:FastStringCodec.java

示例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());
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:12,代碼來源:DottedVersion.java

示例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);
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:16,代碼來源:BuildConfiguration.java

示例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();
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:11,代碼來源:BuildOptions.java

示例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);
}
 
開發者ID:andreynovikov,項目名稱:trekarta,代碼行數:58,代碼來源:TrackManager.java

示例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.");
}
 
開發者ID:jhunters,項目名稱:jprotobuf,代碼行數:62,代碼來源:CodedConstant.java

示例15: deserialize

import com.google.protobuf.CodedInputStream; //導入方法依賴的package包/類
@Override
public Integer deserialize(CodedInputStream codedIn)
    throws SerializationException, IOException {
  return codedIn.readInt32();
}
 
開發者ID:bazelbuild,項目名稱:bazel,代碼行數:6,代碼來源:ObjectCodecsTest.java


注:本文中的com.google.protobuf.CodedInputStream.readInt32方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。