@Override
protected void encode(ChannelHandlerContext tcx, GatelProtocol msg,
ByteBuf out) throws Exception {
out.writeBytes(msg.getHead_data());
out.writeBytes(msg.getCom());
//写入short类型 高位在前 低位在后
out.writeShortLE(msg.getDataLength());
out.writeBytes(msg.getData());
out.writeByte(msg.getCheck());
out.writeByte(msg.getTail());
}
相应的读取
short dataLength = buffer.readShortLE();