szetszwo commented on code in PR #1631:
URL: https://github.com/apache/ratis/pull/1631#discussion_r4239463308


##########
ratis-common/src/main/java/org/apache/ratis/protocol/Message.java:
##########
@@ -65,17 +86,57 @@ static Message valueOf(String string) {
   }
 
   static int getSize(Message message) {
-    return Optional.ofNullable(message).map(Message::size).orElse(0);
+    return message == null ? 0 : message.size();
+  }
+
+  static int getSize(ByteBuffer buffer) {
+    return buffer == null ? 0 : buffer.remaining();
+  }
+
+  static int getSize(ByteString bytes) {
+    return bytes == null ? 0 : bytes.size();
+  }
+
+  /**
+   * Convert the content of the given message to a {@link ByteString}.
+   * When the message supports {@link ByteBuffer},
+   * the buffer is wrapped without copying and {@link #getContent()} is not 
invoked.
+   *
+   * @return the content as a {@link ByteString}, or null if the content is 
null.
+   */
+  static ByteString toByteString(Message message) {

Review Comment:
   @amaliujia , thanks for the update!
   
   We should check if message == null; i.e. 
   ```java
   if (message == null) {
     return null;
   }
   ```
   Otherwise, the change looks good.
   



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