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

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

源代码1 项目: zetasketch   文件: State.java

/**
 * Parses a serialized HyperLogLog++ {@link AggregatorStateProto} and populates this object's
 * fields. If the {@code input} supports aliasing (for byte arrays and {@link ByteBuffer}, see
 * {@link CodedInputStream#enableAliasing(boolean) for details}), {@link #data} and {@link
 * #sparseData} will <em>alias</em> the given bytes &mdash; sharing the same memory.
 *
 * @throws IOException If the stream does not contain a serialized {@link AggregatorStateProto} or
 *     if fields are set that would typically not belong
 */
public void parse(CodedInputStream input) throws IOException {
  // Reset defaults as values set to the default will not be encoded in the protocol buffer.
  clear();

  UnknownFieldSet.Builder ignoredFields = UnknownFieldSet.newBuilder();
  while (!input.isAtEnd()) {
    int tag = input.readTag();
    switch (tag) {
      case TYPE_TAG:
        type = AggregatorType.forNumber(input.readEnum());
        break;
      case NUM_VALUES_TAG:
        numValues = input.readInt64();
        break;
      case ENCODING_VERSION_TAG:
        encodingVersion = input.readInt32();
        break;
      case VALUE_TYPE_TAG:
        valueType = ValueType.forNumber(input.readEnum());
        break;
      case HYPERLOGLOGPLUS_UNIQUE_STATE_TAG:
        parseHll(input, input.readInt32());
        break;
      default:
        ignoredFields.mergeFieldFrom(tag, input);
    }
  }
}
 
源代码2 项目: lams   文件: XProtocolDecoder.java

@Override
public <T> T decodeTime(byte[] bytes, int offset, int length, ValueFactory<T> vf) {
    try {
        CodedInputStream inputStream = CodedInputStream.newInstance(bytes, offset, length);
        boolean negative = inputStream.readRawByte() > 0;
        int hours = 0;
        int minutes = 0;
        int seconds = 0;

        int nanos = 0;

        if (!inputStream.isAtEnd()) {
            hours = (int) inputStream.readInt64();
            if (!inputStream.isAtEnd()) {
                minutes = (int) inputStream.readInt64();
                if (!inputStream.isAtEnd()) {
                    seconds = (int) inputStream.readInt64();
                    if (!inputStream.isAtEnd()) {
                        nanos = 1000 * (int) inputStream.readInt64();
                    }
                }
            }
        }

        return vf.createFromTime(negative ? -1 * hours : hours, minutes, seconds, nanos);
    } catch (IOException e) {
        throw new DataReadException(e);
    }
}
 
源代码3 项目: lams   文件: XProtocolDecoder.java

@Override
public <T> T decodeTimestamp(byte[] bytes, int offset, int length, ValueFactory<T> vf) {
    try {
        CodedInputStream inputStream = CodedInputStream.newInstance(bytes, offset, length);
        int year = (int) inputStream.readUInt64();
        int month = (int) inputStream.readUInt64();
        int day = (int) inputStream.readUInt64();

        // do we have a time too?
        if (inputStream.getBytesUntilLimit() > 0) {
            int hours = 0;
            int minutes = 0;
            int seconds = 0;

            int nanos = 0;

            if (!inputStream.isAtEnd()) {
                hours = (int) inputStream.readInt64();
                if (!inputStream.isAtEnd()) {
                    minutes = (int) inputStream.readInt64();
                    if (!inputStream.isAtEnd()) {
                        seconds = (int) inputStream.readInt64();
                        if (!inputStream.isAtEnd()) {
                            nanos = 1000 * (int) inputStream.readInt64();
                        }
                    }
                }
            }

            return vf.createFromTimestamp(year, month, day, hours, minutes, seconds, nanos);
        }
        return vf.createFromDate(year, month, day);
    } catch (IOException e) {
        throw new DataReadException(e);
    }
}
 
源代码4 项目: FoxTelem   文件: XProtocolDecoder.java

@Override
public <T> T decodeTime(byte[] bytes, int offset, int length, ValueFactory<T> vf) {
    try {
        CodedInputStream inputStream = CodedInputStream.newInstance(bytes, offset, length);
        boolean negative = inputStream.readRawByte() > 0;
        int hours = 0;
        int minutes = 0;
        int seconds = 0;

        int nanos = 0;

        if (!inputStream.isAtEnd()) {
            hours = (int) inputStream.readInt64();
            if (!inputStream.isAtEnd()) {
                minutes = (int) inputStream.readInt64();
                if (!inputStream.isAtEnd()) {
                    seconds = (int) inputStream.readInt64();
                    if (!inputStream.isAtEnd()) {
                        nanos = 1000 * (int) inputStream.readInt64();
                    }
                }
            }
        }

        return vf.createFromTime(negative ? -1 * hours : hours, minutes, seconds, nanos);
    } catch (IOException e) {
        throw new DataReadException(e);
    }
}
 
源代码5 项目: FoxTelem   文件: XProtocolDecoder.java

@Override
public <T> T decodeTimestamp(byte[] bytes, int offset, int length, ValueFactory<T> vf) {
    try {
        CodedInputStream inputStream = CodedInputStream.newInstance(bytes, offset, length);
        int year = (int) inputStream.readUInt64();
        int month = (int) inputStream.readUInt64();
        int day = (int) inputStream.readUInt64();

        // do we have a time too?
        if (inputStream.getBytesUntilLimit() > 0) {
            int hours = 0;
            int minutes = 0;
            int seconds = 0;

            int nanos = 0;

            if (!inputStream.isAtEnd()) {
                hours = (int) inputStream.readInt64();
                if (!inputStream.isAtEnd()) {
                    minutes = (int) inputStream.readInt64();
                    if (!inputStream.isAtEnd()) {
                        seconds = (int) inputStream.readInt64();
                        if (!inputStream.isAtEnd()) {
                            nanos = 1000 * (int) inputStream.readInt64();
                        }
                    }
                }
            }

            return vf.createFromTimestamp(year, month, day, hours, minutes, seconds, nanos);
        }
        return vf.createFromDate(year, month, day);
    } catch (IOException e) {
        throw new DataReadException(e);
    }
}
 
源代码6 项目: bazel   文件: LongArrayCodec.java

@Override
public long[] deserialize(DeserializationContext context, CodedInputStream codedIn)
    throws SerializationException, IOException {
  long[] result = new long[codedIn.readInt32()];
  for (int i = 0; i < result.length; i++) {
    result[i] = codedIn.readInt64();
  }
  return result;
}
 
源代码7 项目: phoenix-omid   文件: HBaseCommitTable.java

private static long decodeCommitTimestamp(long startTimestamp, byte[] encodedCommitTimestamp) throws IOException {
    CodedInputStream cis = CodedInputStream.newInstance(encodedCommitTimestamp);
    long diff = cis.readInt64();
    return startTimestamp + diff;
}
 
源代码8 项目: 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.");
}
 
源代码9 项目: bazel   文件: UUIDCodec.java

@Override
public UUID deserialize(DeserializationContext unusedContext, CodedInputStream codedIn)
    throws SerializationException, IOException {
  return new UUID(codedIn.readInt64(), codedIn.readInt64());
}
 
源代码10 项目: bazel   文件: LongCodec.java

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