@Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
            throws Exception {
        CompositeByteBuf out;
        if (msg instanceof RedisCommand<?, ?, ?> command) {
            int argsCount = countArgs(command);
            int componentCount = COMMAND_BYTEBUF_COMPONENT_COUNT
                    + argsCount * CommandArgsUtil.ARG_BYTEBUF_COMPONENT_COUNT;
            out = UnpooledByteBufAllocator.DEFAULT.compositeDirectBuffer(componentCount);
            encode(out, command, argsCount);
        } else if (msg instanceof Collection) {
            Collection<RedisCommand<?, ?, ?>> commands = (Collection<RedisCommand<?, ?, ?>>) msg;
            int componentCount = 0;
            for (RedisCommand<?, ?, ?> command : commands) {
                componentCount += COMMAND_BYTEBUF_COMPONENT_COUNT
                        + countArgs(command) * CommandArgsUtil.ARG_BYTEBUF_COMPONENT_COUNT;
            }
            out = UnpooledByteBufAllocator.DEFAULT.compositeDirectBuffer(componentCount);
            for (RedisCommand<?, ?, ?> command : commands) {
                encode(out, command, countArgs(command));
            }
        } else {
            throw new IllegalArgumentException(
                    "Unknown message class: "
                            + msg.getClass()
                                    .getName());
        }
        ctx.write(out, promise);
    }
@author James Chen
@implNote We don't use MessageToByteEncoder because they will release the input buffer while we
          need to reuse the input buffer to compose a composite buffer.
@see CommandEncoder
@see CommandArgsUtil
turms-server-common/src/main/java/im/turms/server/common/storage/redis/command/TurmsCommandEncoder.java