sijie commented on a change in pull request #5123: Modify the schema decode 
method can decode ByteBuf
URL: https://github.com/apache/pulsar/pull/5123#discussion_r322405968
 
 

 ##########
 File path: 
pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/StringSchema.java
 ##########
 @@ -93,6 +102,22 @@ public String decode(byte[] bytes) {
         }
     }
 
+    public String decode(ByteBuf byteBuf) {
+        if (null == byteBuf) {
+            return null;
+        } else {
+            int size = byteBuf.readableBytes();
+            byte[] bytes = tmpBuffer.get();
+            if (size > bytes.length) {
+                bytes = new byte[size * 2];
+                tmpBuffer.set(bytes);
+            }
+            byteBuf.readBytes(bytes, 0, size);
+
+            return new String(bytes, 0, size, charset);
 
 Review comment:
   I think we should create a new buffer for the `String`. because the pass-in 
byte[] will be referenced by the `String` object.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to