ijuma commented on code in PR #19163: URL: https://github.com/apache/kafka/pull/19163#discussion_r1985768753
########## clients/src/main/java/org/apache/kafka/common/protocol/MessageUtil.java: ########## @@ -204,13 +204,17 @@ public static boolean compareRawTaggedFields(List<RawTaggedField> first, } } - public static ByteBuffer toByteBuffer(final Message message, final short version) { + public static Readable toReadable(final Message message, final short version) { ObjectSerializationCache cache = new ObjectSerializationCache(); int messageSize = message.size(cache, version); ByteBufferAccessor bytes = new ByteBufferAccessor(ByteBuffer.allocate(messageSize)); message.write(bytes, cache, version); bytes.flip(); - return bytes.buffer(); + return bytes; + } + + public static ByteBuffer toByteBuffer(final Message message, final short version) { + return ((ByteBufferAccessor) toReadable(message, version)).buffer(); Review Comment: I see a few other unsafe casts in the PR. We should devise a solution that doesn't involve that. ########## clients/src/main/java/org/apache/kafka/common/protocol/MessageUtil.java: ########## @@ -204,13 +204,17 @@ public static boolean compareRawTaggedFields(List<RawTaggedField> first, } } - public static ByteBuffer toByteBuffer(final Message message, final short version) { + public static Readable toReadable(final Message message, final short version) { ObjectSerializationCache cache = new ObjectSerializationCache(); int messageSize = message.size(cache, version); ByteBufferAccessor bytes = new ByteBufferAccessor(ByteBuffer.allocate(messageSize)); message.write(bytes, cache, version); bytes.flip(); - return bytes.buffer(); + return bytes; + } + + public static ByteBuffer toByteBuffer(final Message message, final short version) { + return ((ByteBufferAccessor) toReadable(message, version)).buffer(); Review Comment: I see a few other unsafe casts in the PR. We should devise a solution that doesn't require that. -- 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