实现设计 by Netty

总结几种常见协议在netty上的核心实现逻辑

redis

  1. decode逻辑总结 d1
  2. 抽取公共部分 d2
  3. 概念代码

       while (true) {
           if (!in.isReadable()) {
               break;
           }

           byte first = in.readByte();
           switch (first) {
               case '*':
               case '+':
               case '-':
               case ':': {
                   ByteBuf buf = findSliceRead(in,processor);
                   if (null != buf) {
                       out.add(buf.toString(StandardCharsets.UTF_8));
                   }
               }
               break;
               case '$': {
                   ByteBuf buf = findSliceRead(in,processor);
                   lastLen = Integer.parseInt(buf.toString(StandardCharsets.UTF_8));
                   out.add(lastLen);
                   ByteBuf buf1 = sliceRead(in,lastLen);
                   out.add(buf1.toString(StandardCharsets.UTF_8));
               }
               break;
               default:
                   break;
           }
       }