yew1eb commented on code in PR #3769:
URL: https://github.com/apache/celeborn/pull/3769#discussion_r3719630574
##########
common/src/main/java/org/apache/celeborn/common/network/protocol/Encoders.java:
##########
@@ -20,20 +20,20 @@
import java.nio.charset.StandardCharsets;
import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufUtil;
/** Provides a canonical set of Encoders for simple types. */
public class Encoders {
/** Strings are encoded with their length followed by UTF-8 bytes. */
public static class Strings {
public static int encodedLength(String s) {
- return 4 + s.getBytes(StandardCharsets.UTF_8).length;
+ return 4 + ByteBufUtil.utf8Bytes(s);
}
public static void encode(ByteBuf buf, String s) {
- byte[] bytes = s.getBytes(StandardCharsets.UTF_8);
- buf.writeInt(bytes.length);
- buf.writeBytes(bytes);
+ buf.writeInt(ByteBufUtil.utf8Bytes(s));
+ ByteBufUtil.writeUtf8(buf, s);
Review Comment:
Thanks for the suggestions!
Done.
--
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]