dajac commented on code in PR #13240: URL: https://github.com/apache/kafka/pull/13240#discussion_r1121499577
########## clients/src/main/java/org/apache/kafka/common/requests/OffsetCommitResponse.java: ########## @@ -188,12 +188,73 @@ public Builder merge( } }); } - return this; } - public OffsetCommitResponse build() { + public final OffsetCommitResponse build() { return new OffsetCommitResponse(data); } + + protected abstract void validate(String topicName, Uuid topicId); + + protected abstract T classifer(String topicName, Uuid topicId); + + protected abstract OffsetCommitResponseTopic newTopic(String topicName, Uuid topicId); + private OffsetCommitResponseTopic getOrCreateTopic(String topicName, Uuid topicId) { + T topicKey = classifer(topicName, topicId); + OffsetCommitResponseTopic topic = topics.get(topicKey); + if (topic == null) { + topic = newTopic(topicName, topicId); + data.topics().add(topic); + topics.put(topicKey, topic); + } + return topic; + } + } + + public static final class BuilderByTopicId extends Builder<Uuid> { + protected BuilderByTopicId(short version) { + super(version); + } + + @Override + protected void validate(String topicName, Uuid topicId) { + if (topicId == null || Uuid.ZERO_UUID.equals(topicId)) + throw new UnsupportedVersionException("OffsetCommitResponse version " + version + + " does not support zero topic IDs."); + } + + @Override + protected Uuid classifer(String topicName, Uuid topicId) { + return topicId; + } + + @Override + protected OffsetCommitResponseTopic newTopic(String topicName, Uuid topicId) { + return new OffsetCommitResponseTopic().setName(null).setTopicId(topicId); Review Comment: We could get this in the base class and always set both of them. The serialization framework knows what to do. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org