franz1981 commented on code in PR #16595:
URL: https://github.com/apache/kafka/pull/16595#discussion_r1679214441


##########
clients/src/main/java/org/apache/kafka/common/utils/ByteBufferOutputStream.java:
##########
@@ -71,11 +74,138 @@ public void write(byte[] bytes, int off, int len) {
         buffer.put(bytes, off, len);
     }
 
+    @Override
+    public void writeBoolean(boolean v) throws IOException {
+        ensureRemaining(1);
+        buffer.put((byte) (v ? 1 : 0));
+    }
+
+    @Override
+    public void writeByte(int v) throws IOException {
+        ensureRemaining(1);
+        buffer.put((byte) v);
+    }
+
+    @Override
+    public void writeShort(int v) throws IOException {
+        ensureRemaining(2);
+        writeByte((v >>> 8) & 0xFF);
+        writeByte((v >>> 0) & 0xFF);
+    }
+
+    @Override
+    public void writeChar(int v) throws IOException {
+        ensureRemaining(2);
+        writeByte((v >>> 8) & 0xFF);
+        writeByte((v >>> 0) & 0xFF);
+    }
+
+    @Override
+    public void writeInt(int v) throws IOException {
+        ensureRemaining(4);
+        buffer.put((byte)((v >>> 24) & 0xFF));
+        buffer.put((byte)((v >>> 16) & 0xFF));
+        buffer.put((byte)((v >>>  8) & 0xFF));
+        buffer.put((byte)((v >>>  0) & 0xFF));    }
+
+    @Override
+    public void writeLong(long v) throws IOException {
+        ensureRemaining(8);
+        buffer.put((byte)(v >>> 56));
+        buffer.put((byte)(v >>> 48));
+        buffer.put((byte)(v >>> 40));
+        buffer.put((byte)(v >>> 32));
+        buffer.put((byte)(v >>> 24));
+        buffer.put((byte)(v >>> 16));
+        buffer.put((byte)(v >>>  8));
+        buffer.put((byte)(v >>>  0));
+
+    }
+
+    @Override
+    public void writeFloat(float v) throws IOException {
+        writeInt(Float.floatToIntBits(v));
+    }
+
+    @Override
+    public void writeDouble(double v) throws IOException {
+        writeLong(Double.doubleToLongBits(v));
+    }
+
+    @Override
+    public void writeBytes(String s) throws IOException {
+        int len = s.length();
+        ensureRemaining(len);
+        for (int i = 0 ; i < len ; i++) {
+            buffer.put((byte)s.charAt(i));
+        }
+    }
+
+    @Override
+    public void writeChars(String s) throws IOException {
+        int len = s.length();
+        ensureRemaining(len*2);
+        for (int i = 0 ; i < len ; i++) {
+            int v = s.charAt(i);
+            buffer.put((byte) ((v >>> 8) & 0xFF));

Review Comment:
   use `putShort(offset, short)` with the right endianess
   and move the position just once at the end.
   There's no point to move positions so often in a tight loop, which can 
happen just once
   



-- 
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