/**decoder和encoder,如果不需要解析,就使用系统的

* ch.pipeline().addLast(new StringDecoder());

* ch.pipeline().addLast(new StringEncoder());

* 如果使用自己的规则解析,那就写自己的,就如下面

* ch.pipeline().addLast("decoder", new MyMessageDecoder());

*ch.pipeline().addLast("encoder", new MyMessageEncoder());

*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

*/

 

//定长解码器

ch.pipeline().addLast(new StringDecoder(Charset.forName("GBK")));

ch.pipeline().addLast(new StringEncoder(Charset.forName("UTF-8")));
ch.pipeline().addLast(new FixedLengthFrameDecoder(30));//设置定长解码器 长度设置为30
ch.pipeline().addLast(new StringDecoder());//设置字符串解码器 自动将报文转为字符串


//回车换行解码器(\n\r)
ch.pipeline().addLast(new LineBasedFrameDecoder(1024));
ch.pipeline().addLast(new StringDecoder());
```

 

 

markReaderIndex()    //标记一下当前的readIndex的位置

readBytes()       //转移这个缓冲区的数据到指定的目的地 in.readBytes(byte[]);转移in中的字节到byte数组,转移的长度就是byte的长度。

readableBytes()       //

readShort()     //读取两个字节short数据

readInt()       //读取四个字节int数据

readBte()      //读取一个字节

final ByteBuf bbBuf = Unpooled.copiedBuffer(message.data).order(
                    ByteOrder.LITTLE_ENDIAN);

相关文章:

  • 2021-08-20
  • 2021-06-28
  • 2021-11-26
  • 2021-11-10
  • 2021-10-23
  • 2022-01-20
  • 2021-08-15
猜你喜欢
  • 2021-05-02
  • 2021-11-14
  • 2021-04-17
  • 2021-07-27
  • 2021-07-20
  • 2021-06-10
  • 2021-08-29
相关资源
相似解决方案