use of org.apache.kafka.common.message.ConsumerProtocolAssignment in project kafka by apache.
the class ConsumerProtocol method deserializeAssignment.
public static Assignment deserializeAssignment(final ByteBuffer buffer, short version) {
version = checkAssignmentVersion(version);
try {
ConsumerProtocolAssignment data = new ConsumerProtocolAssignment(new ByteBufferAccessor(buffer), version);
List<TopicPartition> assignedPartitions = new ArrayList<>();
for (ConsumerProtocolAssignment.TopicPartition tp : data.assignedPartitions()) {
for (Integer partition : tp.partitions()) {
assignedPartitions.add(new TopicPartition(tp.topic(), partition));
}
}
return new Assignment(assignedPartitions, data.userData() != null ? data.userData().duplicate() : null);
} catch (BufferUnderflowException e) {
throw new SchemaException("Buffer underflow while parsing consumer protocol's assignment", e);
}
}
use of org.apache.kafka.common.message.ConsumerProtocolAssignment in project kafka by apache.
the class ConsumerProtocol method serializeAssignment.
public static ByteBuffer serializeAssignment(final Assignment assignment, short version) {
version = checkAssignmentVersion(version);
ConsumerProtocolAssignment data = new ConsumerProtocolAssignment();
data.setUserData(assignment.userData() != null ? assignment.userData().duplicate() : null);
assignment.partitions().forEach(tp -> {
ConsumerProtocolAssignment.TopicPartition partition = data.assignedPartitions().find(tp.topic());
if (partition == null) {
partition = new ConsumerProtocolAssignment.TopicPartition().setTopic(tp.topic());
data.assignedPartitions().add(partition);
}
partition.partitions().add(tp.partition());
});
return MessageUtil.toVersionPrefixedByteBuffer(version, data);
}
Aggregations