GroupOffsetFetchResponse.fromBytes constructor
GroupOffsetFetchResponse.fromBytes(
- List<int> bytes, {
- int apiVersion = 5,
})
Implementation
factory GroupOffsetFetchResponse.fromBytes(List<int> bytes,
{int apiVersion = 5}) {
if (apiVersion != 5 && apiVersion != 7) {
throw ArgumentError('Only OffsetFetch v5 and v7 are supported');
}
final flexible = apiVersion == 7;
final r = _reader(bytes);
final id = r.readInt32();
if (flexible) _tags(r); // Response header v1.
final throttle = r.readInt32();
final count = flexible ? _compactCount(r, 3) : _count(r, 6);
final topics = <GroupOffsetFetchTopicResponse>[];
for (var i = 0; i < count; i++) {
final name = flexible ? _compactString(r)! : _requiredString(r);
final partitionCount = flexible ? _compactCount(r, 20) : _count(r, 20);
final partitions = <GroupOffsetFetchPartitionResponse>[];
for (var j = 0; j < partitionCount; j++) {
final index = _partition(r);
final offset = r.readInt64();
final epoch = r.readInt32();
if (offset < -1 || epoch < -1) {
throw const FormatException(
'Invalid committed offset or leader epoch');
}
final metadata =
flexible ? _compactString(r, nullable: true) : r.readString();
partitions.add(GroupOffsetFetchPartitionResponse(
index, offset, epoch, metadata, r.readInt16()));
if (flexible) _tags(r);
}
if (flexible) _tags(r);
topics.add(GroupOffsetFetchTopicResponse(name, partitions));
}
final error = r.readInt16();
if (flexible) _tags(r);
_end(r);
return GroupOffsetFetchResponse(id, throttle, topics, error);
}