Java Code Examples for com.google.protobuf.CodedOutputStream#writeInt64NoTag()

The following examples show how to use com.google.protobuf.CodedOutputStream#writeInt64NoTag() . 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 6 votes vote down vote up
public void writeTo(CodedOutputStream stream) throws IOException {
  // We use the NoTag write methods for consistency with the parsing functions and for
  // consistency with the variable-length writes where we can't use any convenience function.
  stream.writeUInt32NoTag(TYPE_TAG);
  stream.writeEnumNoTag(type.getNumber());

  stream.writeUInt32NoTag(NUM_VALUES_TAG);
  stream.writeInt64NoTag(numValues);

  if (encodingVersion != DEFAULT_ENCODING_VERSION) {
    stream.writeUInt32NoTag(ENCODING_VERSION_TAG);
    stream.writeInt32NoTag(encodingVersion);
  }

  if (!valueType.equals(DEFAULT_VALUE_TYPE)) {
    stream.writeUInt32NoTag(VALUE_TYPE_TAG);
    stream.writeEnumNoTag(valueType.getNumber());
  }

  stream.writeUInt32NoTag(HYPERLOGLOGPLUS_UNIQUE_STATE_TAG);
  stream.writeUInt32NoTag(getSerializedHllSize());
  writeHllTo(stream);
}
 
Example 2
Source File: HBaseCommitTable.java    From phoenix-omid with Apache License 2.0 5 votes vote down vote up
private static byte[] encodeCommitTimestamp(long startTimestamp, long commitTimestamp) throws IOException {
    assert (startTimestamp < commitTimestamp);
    long diff = commitTimestamp - startTimestamp;
    byte[] bytes = new byte[CodedOutputStream.computeInt64SizeNoTag(diff)];
    CodedOutputStream cos = CodedOutputStream.newInstance(bytes);
    cos.writeInt64NoTag(diff);
    cos.flush();
    return bytes;

}
 
Example 3
Source File: LongArrayCodec.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
public void serialize(SerializationContext context, long[] obj, CodedOutputStream codedOut)
    throws SerializationException, IOException {
  codedOut.writeInt32NoTag(obj.length);
  for (long l : obj) {
    codedOut.writeInt64NoTag(l);
  }
}
 
Example 4
Source File: CodedConstant.java    From jprotobuf with Apache License 2.0 4 votes vote down vote up
/**
 * Write a field of arbitrary type, without its tag, to the stream.
 *
 * @param output The output stream.
 * @param type The field's type.
 * @param value Object representing the field's value. Must be 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 void writeElementNoTag(final CodedOutputStream output, final WireFormat.FieldType type,
        final Object value) throws IOException {
    switch (type) {
        case DOUBLE:
            output.writeDoubleNoTag((Double) value);
            break;
        case FLOAT:
            output.writeFloatNoTag((Float) value);
            break;
        case INT64:
            output.writeInt64NoTag((Long) value);
            break;
        case UINT64:
            output.writeUInt64NoTag((Long) value);
            break;
        case INT32:
            output.writeInt32NoTag((Integer) value);
            break;
        case FIXED64:
            output.writeFixed64NoTag((Long) value);
            break;
        case FIXED32:
            output.writeFixed32NoTag((Integer) value);
            break;
        case BOOL:
            output.writeBoolNoTag((Boolean) value);
            break;
        case STRING:
            output.writeStringNoTag((String) value);
            break;
        // group not support yet
        // case GROUP : output.writeGroupNoTag ((MessageLite) value); break;
        case MESSAGE:
            writeObject(output, 0, FieldType.OBJECT, value, false, false);
            break;
        case BYTES:
            if (value instanceof ByteString) {
                output.writeBytesNoTag((ByteString) value);
            } else {
                byte[] v;
                if (value instanceof Byte[]) {
                    v = toByteArray((Byte[]) value);
                } else {
                    v = (byte[]) value;
                }
                output.writeByteArrayNoTag(v);
            }
            break;
        case UINT32:
            output.writeUInt32NoTag((Integer) value);
            break;
        case SFIXED32:
            output.writeSFixed32NoTag((Integer) value);
            break;
        case SFIXED64:
            output.writeSFixed64NoTag((Long) value);
            break;
        case SINT32:
            output.writeSInt32NoTag((Integer) value);
            break;
        case SINT64:
            output.writeSInt64NoTag((Long) value);
            break;

        case ENUM:
            if (value instanceof Internal.EnumLite) {
                output.writeEnumNoTag(((Internal.EnumLite) value).getNumber());
            } else {

                if (value instanceof EnumReadable) {
                    output.writeEnumNoTag(((EnumReadable) value).value());
                } else if (value instanceof Enum) {
                    output.writeEnumNoTag(((Enum) value).ordinal());
                } else {
                    output.writeEnumNoTag(((Integer) value).intValue());
                }

            }
            break;
    }
}
 
Example 5
Source File: UUIDCodec.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(SerializationContext unusedContext, UUID uuid, CodedOutputStream codedOut)
    throws SerializationException, IOException {
  codedOut.writeInt64NoTag(uuid.getMostSignificantBits());
  codedOut.writeInt64NoTag(uuid.getLeastSignificantBits());
}
 
Example 6
Source File: LongCodec.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(SerializationContext context, Long value, CodedOutputStream codedOut)
    throws IOException {
  codedOut.writeInt64NoTag(value);
}
 
Example 7
Source File: DurationCodec.java    From bazel with Apache License 2.0 4 votes vote down vote up
@Override
public void serialize(SerializationContext context, Duration obj, CodedOutputStream codedOut)
    throws SerializationException, IOException {
  codedOut.writeInt64NoTag(obj.getSeconds());
  codedOut.writeInt32NoTag(obj.getNano());
}