UNPKG

@platformatic/kafka

Version:

Modern and performant client for Apache Kafka

69 lines (68 loc) 2.67 kB
import { ResponseError } from "../../errors.js"; import { Writer } from "../../protocol/writer.js"; import { createAPI } from "../definitions.js"; /* OffsetCommit Request (Version: 9) => group_id generation_id_or_member_epoch member_id group_instance_id [topics] TAG_BUFFER group_id => COMPACT_STRING generation_id_or_member_epoch => INT32 member_id => COMPACT_STRING group_instance_id => COMPACT_NULLABLE_STRING topics => name [partitions] TAG_BUFFER name => COMPACT_STRING partitions => partition_index committed_offset committed_leader_epoch committed_metadata TAG_BUFFER partition_index => INT32 committed_offset => INT64 committed_leader_epoch => INT32 committed_metadata => COMPACT_NULLABLE_STRING */ export function createRequest(groupId, generationIdOrMemberEpoch, memberId, groupInstanceId, topics) { return Writer.create() .appendString(groupId) .appendInt32(generationIdOrMemberEpoch) .appendString(memberId) .appendString(groupInstanceId) .appendArray(topics, (w, t) => { w.appendString(t.name).appendArray(t.partitions, (w, p) => { w.appendInt32(p.partitionIndex) .appendInt64(p.committedOffset) .appendInt32(p.committedLeaderEpoch) .appendString(p.committedMetadata); }); }) .appendTaggedFields(); } /* OffsetCommit Response (Version: 9) => throttle_time_ms [topics] TAG_BUFFER throttle_time_ms => INT32 topics => name [partitions] TAG_BUFFER name => COMPACT_STRING partitions => partition_index error_code TAG_BUFFER partition_index => INT32 error_code => INT16 */ export function parseResponse(_correlationId, apiKey, apiVersion, reader) { const errors = []; const response = { throttleTimeMs: reader.readInt32(), topics: reader.readArray((r, i) => { return { name: r.readString(), partitions: r.readArray((r, j) => { const partition = { partitionIndex: r.readInt32(), errorCode: r.readInt16() }; if (partition.errorCode !== 0) { errors.push([`/topics/${i}/partitions/${j}`, partition.errorCode]); } return partition; }) }; }) }; if (errors.length) { throw new ResponseError(apiKey, apiVersion, Object.fromEntries(errors), response); } return response; } export const api = createAPI(8, 9, createRequest, parseResponse);