in impl/src/main/java/org/apache/rocketmq/remoting/impl/command/CodecHelper.java [119:174]
public static RemotingCommand decode(final RemotingBuffer in) {
RemotingCommandImpl cmd = new RemotingCommandImpl();
cmd.cmdCode(in.readShort());
cmd.cmdVersion(in.readShort());
cmd.requestID(in.readInt());
cmd.trafficType(TrafficType.parse(in.readByte()));
cmd.opCode(in.readShort());
short remarkLen = in.readShort();
if (remarkLen > 0) {
byte[] bytes = new byte[remarkLen];
in.readBytes(bytes);
String str = new String(bytes, REMOTING_CHARSET);
cmd.remark(str);
}
short propsSize = in.readShort();
int propsLen = 0;
if (propsSize > 0) {
for (int i = 0; i < propsSize; i++) {
short length = in.readShort();
if (length > 0) {
byte[] bytes = new byte[length];
in.readBytes(bytes);
String str = new String(bytes, REMOTING_CHARSET);
int index = str.indexOf(PROPERTY_SEPARATOR);
if (index > 0) {
String key = str.substring(0, index);
String value = str.substring(index + 1);
cmd.property(key, value);
}
}
propsLen += 2;
propsLen += length;
if (propsLen > PROPERTY_MAX_LEN) {
throw new RemotingCodecException(String.format("Properties total len: %d over max limit: %d", propsLen, PROPERTY_MAX_LEN));
}
}
}
int payloadLen = in.readInt();
if (payloadLen > PAYLOAD_MAX_LEN) {
throw new RemotingCodecException(String.format("Payload len: %d over max limit: %d", payloadLen, PAYLOAD_MAX_LEN));
}
if (payloadLen > 0) {
byte[] bytes = new byte[payloadLen];
in.readBytes(bytes);
cmd.payload(bytes);
}
return cmd;
}