Java Code Examples for org.apache.kafka.common.protocol.types.Struct#writeTo()

The following examples show how to use org.apache.kafka.common.protocol.types.Struct#writeTo() . 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: GroupMetadataConstants.java    From kop with Apache License 2.0 5 votes vote down vote up
static byte[] offsetCommitKey(String group,
                              TopicPartition topicPartition,
                              short versionId) {
    Struct key = new Struct(CURRENT_OFFSET_KEY_SCHEMA);
    key.set(OFFSET_KEY_GROUP_FIELD, group);
    key.set(OFFSET_KEY_TOPIC_FIELD, topicPartition.topic());
    key.set(OFFSET_KEY_PARTITION_FIELD, topicPartition.partition());

    ByteBuffer byteBuffer = ByteBuffer.allocate(2 /* version */ + key.sizeOf());
    byteBuffer.putShort(CURRENT_OFFSET_KEY_SCHEMA_VERSION);
    key.writeTo(byteBuffer);
    return byteBuffer.array();
}
 
Example 2
Source File: GroupMetadataConstants.java    From kop with Apache License 2.0 5 votes vote down vote up
/**
 * Generates the key for group metadata message for given group.
 *
 * @return key bytes for group metadata message
 */
static byte[] groupMetadataKey(String group) {
    Struct key = new Struct(CURRENT_GROUP_KEY_SCHEMA);
    key.set(GROUP_KEY_GROUP_FIELD, group);
    ByteBuffer byteBuffer = ByteBuffer.allocate(2 /* version */ + key.sizeOf());
    byteBuffer.putShort(CURRENT_GROUP_KEY_SCHEMA_VERSION);
    key.writeTo(byteBuffer);
    return byteBuffer.array();
}
 
Example 3
Source File: GroupMetadataConstants.java    From kop with Apache License 2.0 5 votes vote down vote up
/**
 * Generates the payload for offset commit message from given offset and metadata.
 *
 * @param offsetAndMetadata consumer's current offset and metadata
 * @return payload for offset commit message
 */
static byte[] offsetCommitValue(OffsetAndMetadata offsetAndMetadata) {
    Struct value = new Struct(CURRENT_OFFSET_VALUE_SCHEMA);
    value.set(OFFSET_VALUE_OFFSET_FIELD_V1, offsetAndMetadata.offset());
    value.set(OFFSET_VALUE_METADATA_FIELD_V1, offsetAndMetadata.metadata());
    value.set(OFFSET_VALUE_COMMIT_TIMESTAMP_FIELD_V1, offsetAndMetadata.commitTimestamp());
    value.set(OFFSET_VALUE_EXPIRE_TIMESTAMP_FIELD_V1, offsetAndMetadata.expireTimestamp());
    ByteBuffer byteBuffer = ByteBuffer.allocate(2 /* version */ + value.sizeOf());
    byteBuffer.putShort(CURRENT_GROUP_VALUE_SCHEMA_VERSION);
    value.writeTo(byteBuffer);
    return byteBuffer.array();
}
 
Example 4
Source File: Response.java    From DataLink with Apache License 2.0 5 votes vote down vote up
private ByteBuffer serialize(ResponseHeader header, Struct body) {
    ByteBuffer buffer = ByteBuffer.allocate(header.sizeOf() + body.sizeOf());
    header.writeTo(buffer);
    body.writeTo(buffer);
    buffer.rewind();
    return buffer;
}