@Override
    public <T extends RequestCommand> boolean serializeHeader(T request, InvokeContext invokeContext)
                                                                                                     throws SerializationException {

        final RpcRequestCommand cmd = (RpcRequestCommand) request;
        final Message msg = (Message) cmd.getRequestObject();
        if (msg instanceof RpcRequests.AppendEntriesRequest) {
            final RpcRequests.AppendEntriesRequest req = (RpcRequests.AppendEntriesRequest) msg;
            final RpcRequests.AppendEntriesRequestHeader.Builder hb = RpcRequests.AppendEntriesRequestHeader
                .newBuilder() //
                .setGroupId(req.getGroupId()) //
                .setPeerId(req.getPeerId()) //
                .setServerId(req.getServerId());
            cmd.setHeader(hb.build().toByteArray());
            return true;
        }

        return false;
    }
RPC custom serializer based on protobuf
@author boyan (boyan@alibaba-inc.com)

2018-Mar-26 4:43:21 PM
jraft-core/src/main/java/com/alipay/sofa/jraft/rpc/ProtobufSerializer.java