@Override
                                                          public ByteBuf cumulate(ByteBufAllocator alloc,
                                                                                  ByteBuf cumulation,
                                                                                  ByteBuf in) {
                                                              ByteBuf buffer;
                                                              if (cumulation.refCnt() > 1) {
                                                                  // Expand cumulation (by replace it) when the refCnt is greater then 1 which may happen when the user
                                                                  // use slice().retain() or duplicate().retain().
                                                                  //
                                                                  // See:
                                                                  // - https://github.com/netty/netty/issues/2327
                                                                  // - https://github.com/netty/netty/issues/1764
                                                                  buffer = expandCumulation(alloc,
                                                                      cumulation,
                                                                      in.readableBytes());
                                                                  buffer.writeBytes(in);
                                                                  in.release();
                                                              } else {
                                                                  CompositeByteBuf composite;
                                                                  if (cumulation instanceof CompositeByteBuf) {
                                                                      composite = (CompositeByteBuf) cumulation;
                                                                  } else {
                                                                      int readable = cumulation
                                                                          .readableBytes();
                                                                      composite = alloc
                                                                          .compositeBuffer();
                                                                      composite.addComponent(
                                                                          cumulation).writerIndex(
                                                                          readable);
                                                                  }
                                                                  composite
                                                                      .addComponent(in)
                                                                      .writerIndex(
                                                                          composite.writerIndex()
                                                                                  + in.readableBytes());
                                                                  buffer = composite;
                                                              }
                                                              return buffer;
                                                          }
Cumulate {@link ByteBuf}s by add them to a {@link CompositeByteBuf} and so do no memory copy whenever possible.
Be aware that {@link CompositeByteBuf} use a more complex indexing implementation so depending on your use-case
and the decoder implementation this may be slower then just use the {@link #MERGE_CUMULATOR}.
src/main/java/com/alipay/remoting/codec/AbstractBatchDecoder.java