com.google.protobuf.CodedInputStream# readInt32 ( ) 源码实例Demo

下面列出了com.google.protobuf.CodedInputStream# readInt32 ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: bazel   文件: Memoizer.java

private <T> T deserializeMemoAfterContent(
    DeserializationContext context, ObjectCodec<T> codec, CodedInputStream codedIn)
    throws SerializationException, IOException {
  T value = castedDeserialize(context, codec, codedIn);
  int id = codedIn.readInt32();
  // If deserializing the children caused the parent object itself to be deserialized due to
  // a cycle, then there's now a memo entry for the parent. Reuse that object, discarding
  // the one we were trying to construct here, so as to avoid creating duplicate objects in
  // the object graph.
  Object cyclicallyCreatedObject = memo.lookup(id);
  if (cyclicallyCreatedObject != null) {
    return safeCast(cyclicallyCreatedObject, codec);
  } else {
    memo.memoize(id, value);
    return value;
  }
}
 
源代码2 项目: bazel   文件: ImmutableBiMapCodec.java

@Override
public ImmutableBiMap<K, V> deserialize(DeserializationContext context, CodedInputStream codedIn)
    throws SerializationException, IOException {

  int length = codedIn.readInt32();
  if (length < 0) {
    throw new SerializationException("Expected non-negative length: " + length);
  }

  ImmutableBiMap.Builder<K, V> builder =
      ImmutableMapCodec.deserializeEntries(
          ImmutableBiMap.builderWithExpectedSize(length), length, context, codedIn);

  try {
    return builder.build();
  } catch (IllegalArgumentException e) {
    throw new SerializationException(
        "Duplicate keys during ImmutableBiMapCodec deserialization", e);
  }
}
 
源代码3 项目: bazel   文件: MethodCodec.java

@Override
public Method deserialize(DeserializationContext context, CodedInputStream codedIn)
    throws SerializationException, IOException {
  Class<?> clazz = context.deserialize(codedIn);
  String name = context.deserialize(codedIn);

  Class<?>[] parameters = new Class<?>[codedIn.readInt32()];
  for (int i = 0; i < parameters.length; i++) {
    parameters[i] = context.deserialize(codedIn);
  }
  try {
    return clazz.getDeclaredMethod(name, parameters);
  } catch (NoSuchMethodException e) {
    throw new SerializationException(
        "Couldn't get method "
            + name
            + " in "
            + clazz
            + " with parameters "
            + Arrays.toString(parameters),
        e);
  }
}
 
源代码4 项目: bazel   文件: MultimapCodec.java

@Override
public ImmutableMultimap<K, V> deserialize(
    DeserializationContext context, CodedInputStream codedIn)
    throws SerializationException, IOException {
  ImmutableMultimap.Builder<K, V> result;
  if (codedIn.readBool()) {
    result = ImmutableListMultimap.builder();
  } else {
    result = ImmutableSetMultimap.builder();
  }
  int length = codedIn.readInt32();
  for (int i = 0; i < length; i++) {
    K key = context.deserialize(codedIn);
    Collection<V> values = context.deserialize(codedIn);
    result.putAll(key, values);
  }
  return result.build();
}
 
源代码5 项目: bazel   文件: ImmutableTableCodec.java

@Override
public ImmutableTable<R, C, V> deserialize(
    DeserializationContext context, CodedInputStream codedIn)
    throws SerializationException, IOException {
  int length = codedIn.readInt32();
  if (length < 0) {
    throw new SerializationException("Expected non-negative length: " + length);
  }
  ImmutableTable.Builder<R, C, V> builder = ImmutableTable.builder();
  for (int i = 0; i < length; i++) {
    builder.put(
        /*rowKey=*/ context.deserialize(codedIn),
        /*columnKey=*/ context.deserialize(codedIn),
        /*value=*/ context.deserialize(codedIn));
  }
  return builder.build();
}
 
源代码6 项目: zetasketch   文件: State.java

/**
 * Parses a {@link HyperLogLogPlusUniqueStateProto} message. Since the message is nested within an
 * {@link AggregatorStateProto}, we limit ourselves to reading only the bytes of the specified
 * message length.
 */
private void parseHll(CodedInputStream input, int size) throws IOException {
  int limit = input.getTotalBytesRead() + size;

  ByteBuffer buffer;
  UnknownFieldSet.Builder ignoredFields = UnknownFieldSet.newBuilder();
  while (input.getTotalBytesRead() < limit && !input.isAtEnd()) {
    int tag = input.readTag();
    switch (tag) {
      case SPARSE_SIZE_TAG:
        sparseSize = input.readInt32();
        break;
      case PRECISION_OR_NUM_BUCKETS_TAG:
        precision = input.readInt32();
        break;
      case SPARSE_PRECISION_OR_NUM_BUCKETS_TAG:
        sparsePrecision = input.readInt32();
        break;
      case DATA_TAG:
        buffer = input.readByteBuffer();
        data = ByteSlice.copyOnWrite(buffer);
        break;
      case SPARSE_DATA_TAG:
        buffer = input.readByteBuffer();
        sparseData = GrowingByteSlice.copyOnWrite(buffer);
        break;
      default:
        ignoredFields.mergeFieldFrom(tag, input);
    }
  }
}
 
源代码7 项目: unitime   文件: ReplayLogTest.java

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;
}
 
源代码8 项目: bazel   文件: SerializationContextTest.java

@Override
public ImmutableList<Object> deserialize(
    DeserializationContext context, CodedInputStream codedIn)
    throws SerializationException, IOException {
  context = context.getMemoizingContext();
  int size = codedIn.readInt32();
  ImmutableList.Builder<Object> builder = ImmutableList.builder();
  for (int i = 0; i < size; i++) {
    builder.add(context.<Object>deserialize(codedIn));
  }
  return builder.build();
}
 
源代码9 项目: bazel   文件: StringLiteral.java

@Override
public StringLiteral deserialize(DeserializationContext context, CodedInputStream in)
    throws SerializationException, IOException {
  String value =
      context.deserializeWithAdHocMemoizationStrategy(in, MemoizationStrategy.MEMOIZE_AFTER);
  int startOffset = in.readInt32();
  int endOffset = in.readInt32();
  FileLocations locs = context.deserialize(in);
  return new StringLiteral(locs, startOffset, value, endOffset);
}
 
源代码10 项目: bazel   文件: ImmutableListCodec.java

@Override
public ImmutableList<T> deserialize(DeserializationContext context, 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(context, codedIn));
  }
  return builder.build();
}
 
源代码11 项目: bazel   文件: HashMapCodec.java

@Override
public LinkedHashMap<K, V> deserialize(DeserializationContext context, CodedInputStream codedIn)
    throws SerializationException, IOException {
  int size = codedIn.readInt32();
  // Load factor is 0.75, so we need an initial capacity of 4/3 actual size to avoid rehashing.
  LinkedHashMap<K, V> result = new LinkedHashMap<>(4 * size / 3);
  for (int i = 0; i < size; i++) {
    result.put(context.deserialize(codedIn), context.deserialize(codedIn));
  }
  return result;
}
 
源代码12 项目: bazel   文件: SerializationContextTest.java

@Override
public ArrayList<?> deserialize(DeserializationContext context, CodedInputStream codedIn)
    throws SerializationException, IOException {
  context = context.getMemoizingContext();
  int size = codedIn.readInt32();
  ArrayList<?> result = new ArrayList<>();
  for (int i = 0; i < size; i++) {
    result.add(context.deserialize(codedIn));
  }
  return result;
}
 
源代码13 项目: bazel   文件: EnumMapCodec.java

@Override
public EnumMap<E, V> deserialize(DeserializationContext context, CodedInputStream codedIn)
    throws SerializationException, IOException {
  int size = codedIn.readInt32();
  Class<E> clazz = context.deserialize(codedIn);
  EnumMap<E, V> result = new EnumMap<>(clazz);
  E[] enums = clazz.getEnumConstants();
  for (int i = 0; i < size; i++) {
    int ordinal = codedIn.readInt32();
    V val = context.deserialize(codedIn);
    result.put(enums[ordinal], val);
  }
  return result;
}
 
源代码14 项目: bazel   文件: NullableListCodec.java

@Override
public List<T> deserialize(DeserializationContext context, CodedInputStream codedIn)
    throws SerializationException, IOException {
  int length = codedIn.readInt32();
  if (length < 0) {
    throw new SerializationException("Expected non-negative length: " + length);
  }

  ArrayList<T> list = new ArrayList<>(length);
  for (int i = 0; i < length; i++) {
    list.add(context.deserialize(codedIn));
  }
  return maybeTransform(list);
}
 
源代码15 项目: bazel   文件: ImmutableListRuntimeCodec.java

@Override
public ImmutableList deserialize(DeserializationContext context, CodedInputStream codedIn)
    throws IOException, SerializationException {
  int size = codedIn.readInt32();
  Object[] list = new Object[size];
  for (int i = 0; i < size; ++i) {
    list[i] = context.deserialize(codedIn);
  }
  return ImmutableList.copyOf(list);
}
 
源代码16 项目: bazel   文件: ImmutableSetRuntimeCodec.java

@SuppressWarnings("unchecked") // Adding object to untyped builder.
@Override
public ImmutableSet deserialize(DeserializationContext context, CodedInputStream codedIn)
    throws SerializationException, IOException {
  int size = codedIn.readInt32();
  ImmutableSet.Builder builder = ImmutableSet.builderWithExpectedSize(size);
  for (int i = 0; i < size; i++) {
    // Don't inline so builder knows this is an object, not an array.
    Object item = context.deserialize(codedIn);
    builder.add(item);
  }
  return builder.build();
}
 
源代码17 项目: snowblossom   文件: TransactionUtil.java

public static ArrayList<ByteString> extractWireFormatTxOut(Transaction tx)
  throws ValidationException
{
  try
  {
    CodedInputStream code_in = CodedInputStream.newInstance(tx.getInnerData().toByteArray());

    ArrayList<ByteString> lst = new ArrayList<>();

    while(true)
    {
      int tag = code_in.readTag();
      if (tag == 0) break;
      
      // The least signficiate 3 bits are the proto field type
      // so shift to get out field number, which is 5 for TranasctionOutput
      if (tag >> 3 == 5)
      {
        ByteArrayOutputStream b_out = new ByteArrayOutputStream();
        CodedOutputStream c_out = CodedOutputStream.newInstance(b_out);
        code_in.skipField(tag, c_out);
        c_out.flush();

        ByteString bs = ByteString.copyFrom(b_out.toByteArray());

        // So funny story...when you get an inner message like this as opposed to just serializing
        // the object, protobuf puts a tag and size on the coded input stream.  So we need to figure
        // out how many bytes that is an trim it off.
        CodedInputStream read_again = CodedInputStream.newInstance(bs.toByteArray());
        // Expected tag
        int tag2 = read_again.readTag();
        // Size of element
        int size = read_again.readInt32();

        // All we really care is how many bytes those two take.  For shorter messages
        // it will be 2, but could be higher if protobuf needs more bytes to encode the size
        int offset = read_again.getTotalBytesRead();

        bs = bs.substring(offset);
        lst.add(bs);
      }
      else
      {
        code_in.skipField(tag);
      }

    }
    return lst;
  }
  catch(java.io.IOException e)
  {
    throw new ValidationException(e);
  }
}
 
源代码18 项目: bazel   文件: ObjectCodecsTest.java

@Override
public Integer deserialize(DeserializationContext context, CodedInputStream codedIn)
    throws SerializationException, IOException {
  return codedIn.readInt32();
}
 
源代码19 项目: jprotobuf   文件: CodedConstant.java

/**
 * 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.readByteArray();
        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.");
}
 
源代码20 项目: bazel   文件: IntegerCodec.java

@Override
public Integer deserialize(DeserializationContext context, CodedInputStream codedIn)
    throws IOException {
  return codedIn.readInt32();
}