Hi there:
Is there any examples about CustomMessage & CustomMessageCodec?
I just saw this example:
and got confused since in the source code e.g. StringMessageCodec:
the transform method is implemented as following and there is a comment
@Override
public String transform(String s) {
// Strings are immutable so just return it
return s;
}
and for other message codecs e.g. json object message codec:
@Override
public JsonObject transform(JsonObject jsonObject) {
return jsonObject.copy();
}
and byte array message codec:
@Override
public byte[] transform(byte[] bytes) {
byte[] copied = new byte[bytes.length];
System.arraycopy(bytes, 0, copied, 0, bytes.length);
return copied;
}
as we can see here, if the message object is not immutable, then in the transform method, we should copy the original obj.
but in the vertx-example custom message codec transform method
it does not copy the original object:
@Override |
| public CustomMessage transform(CustomMessage customMessage) { |
| // If a message is sent *locally* across the event bus. |
| // This example sends message just as is |
| return customMessage; |
| } |
thus my guess here is the example is wrong, but I am not sure about this
any suggestions?
Thanks