Java Code Examples for com.google.protobuf.CodedInputStream#readInt64()

The following examples show how to use com.google.protobuf.CodedInputStream#readInt64() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: State.java    From zetasketch with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
  }
}
 
Example 2
Source File: XProtocolDecoder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example 3
Source File: XProtocolDecoder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example 4
Source File: XProtocolDecoder.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@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);
    }
}
 
Example 5
Source File: XProtocolDecoder.java    From FoxTelem with GNU General Public License v3.0 5 votes vote down vote up
@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);
    }
}
 
Example 6
Source File: LongArrayCodec.java    From bazel with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 7
Source File: HBaseCommitTable.java    From phoenix-omid with Apache License 2.0 4 votes vote down vote up
private static long decodeCommitTimestamp(long startTimestamp, byte[] encodedCommitTimestamp) throws IOException {
    CodedInputStream cis = CodedInputStream.newInstance(encodedCommitTimestamp);
    long diff = cis.readInt64();
    return startTimestamp + diff;
}
 
Example 8
Source File: CodedConstant.java    From jprotobuf with Apache License 2.0 4 votes vote down vote up
/**
 * 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.");
}
 
Example 9
Source File: UUIDCodec.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public UUID deserialize(DeserializationContext unusedContext, CodedInputStream codedIn)
    throws SerializationException, IOException {
  return new UUID(codedIn.readInt64(), codedIn.readInt64());
}
 
Example 10
Source File: LongCodec.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public Long deserialize(DeserializationContext context, CodedInputStream codedIn)
    throws IOException {
  return codedIn.readInt64();
}