franz1981 commented on code in PR #16595:
URL: https://github.com/apache/kafka/pull/16595#discussion_r1679212870
##########
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));
+ buffer.put((byte)((v >>> 0) & 0xFF));
+ }
+ }
+
+ @Override
+ public void writeUTF(String s) throws IOException {
+ int strlen = s.length();
Review Comment:
if the buffer is backed by an array, why not using `String` methods to
encode into it?
--
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]