Analysis of dubbo network communication layer protocol.
It starts with com.alibaba.dubbo.remoting.transport.netty.NettyServer listening to tcp
Then dubbo encapsulates the ByteBuffer into a subclass of ChannelBufferInputStream InputStream
com.alibaba.dubbo.rpc.protocol.dubbo.DubboCodec#decodeBody
Start protocol parsing
int readable = buffer.readableBytes(); byte[] header = new byte[Math.min(readable, HEADER_LENGTH)]; buffer.readBytes(header);
The first 16 bytes are header information
if (readable > 0 && header[0] != MAGIC_HIGH || readable > 1 && header[1] != MAGIC_LOW)
int len = Bytes.bytes2int(header, 12);
long id = Bytes.bytes2long(header, 4);
byte flag = header[2], proto = (byte) (flag & SERIALIZATION_MASK); Serialization s = CodecSupport.getSerialization(channel.getUrl(), proto);
The flag is used to determine the protocol, and choose which serialization to use
dubbo is serialized with Hessian2Serialization
status is used to identify success or failure
finally to
com.alibaba.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation#decode(com.alibaba.dubbo.remoting.Channel, java.io.InputStream) to specifically parse the object
setAttachment(Constants.DUBBO_VERSION_KEY, in.readUTF()); setAttachment(Constants.PATH_KEY, in.readUTF()); setAttachment(Constants.VERSION_KEY, in.readUTF());
Set the relevant value
com.alibaba.com.caucho.hessian.io.Hessian2Input # readObject ()
This method can see how dubbo parses a specific object from the bytes.
There will be time for a more in-depth analysis later.