chia7712 commented on code in PR #17622:
URL: https://github.com/apache/kafka/pull/17622#discussion_r1821008696


##########
clients/src/main/java/org/apache/kafka/common/telemetry/internals/ClientTelemetryUtils.java:
##########
@@ -191,23 +190,22 @@ public static CompressionType 
preferredCompressionType(List<CompressionType> acc
         return CompressionType.NONE;
     }
 
-    public static byte[] compress(MetricsData metrics, CompressionType 
compressionType) throws IOException {
+    public static ByteBuffer compress(MetricsData metrics, CompressionType 
compressionType) throws IOException {
         try (ByteBufferOutputStream compressedOut = new 
ByteBufferOutputStream(512)) {
             Compression compression = Compression.of(compressionType).build();
             try (OutputStream out = compression.wrapForOutput(compressedOut, 
RecordBatch.CURRENT_MAGIC_VALUE)) {
                 metrics.writeTo(out);
             }
             compressedOut.buffer().flip();
-            return Utils.toArray(compressedOut.buffer());
+            return compressedOut.buffer();
         }
     }
 
-    public static ByteBuffer decompress(byte[] metrics, CompressionType 
compressionType) {
-        ByteBuffer data = ByteBuffer.wrap(metrics);
+    public static ByteBuffer decompress(ByteBuffer metrics, CompressionType 
compressionType) {
         Compression compression = Compression.of(compressionType).build();
-        try (InputStream in = compression.wrapForInput(data, 
RecordBatch.CURRENT_MAGIC_VALUE, BufferSupplier.create());
+        try (InputStream in = compression.wrapForInput(metrics, 
RecordBatch.CURRENT_MAGIC_VALUE, BufferSupplier.create());
             ByteBufferOutputStream out = new ByteBufferOutputStream(512)) {
-            byte[] bytes = new byte[data.capacity() * 2];
+            byte[] bytes = new byte[metrics.capacity() * 2];

Review Comment:
   We should call `limit` instead of `capacity`, right? Since the buffer is 
backed by the entire network buffer, `capacity` will return the size of the 
whole network buffer.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to