0

I have a server written in C++ using msgpack-rpc-cpp.

There is a description of a method that the client needs to call remotely on the server:

void SERVER_INIT(TLogicRpc_StParams stParams);

struct TLogicRpc_ServerParams
{
    string destAddr;
    unsigned int destPort = 0;
    bool sslEnable;

    MSGPACK_DEFINE_ARRAY(destAddr, destPort, sslEnable)
};

struct TLogicRpc_ConnParams
{

    int connId = 0;
    string venId;

    MSGPACK_DEFINE_ARRAY(connId, venId)
};

struct TLogicRpc_PostParams
{
    int postId = 0;
    string venId;
    vector<TLogicRpc_ConnParams> conn;
    TLogicRpc_ServerParams server;

    MSGPACK_DEFINE_ARRAY(postId, venId, conn, server)
};

struct TLogicRpc_StParams
{
    string cPVendor;
    string cPModel;
    vector<TLogicRpc_PostParams> posts;
    TLogicRpc_ServerParams server;

    MSGPACK_DEFINE_ARRAY(cPVendor, cPModel, posts, server)
};


How correctly compose in Python a structure described in C++ and send it using msgpack-rpc-python by calling SERVER_INIT?

I assume that the solution must follow one of these paths:

1)

st_params = OrderedDict()
st_params['cPVendor'] = "Vendor"
st_params['cPModel'] = "Model"
st_params['posts'] = []
st_params['server'] = {}
client = msgpackrpc.Client(msgpackrpc.Address("localhost", 8000))
client.call('SERVER_INIT', st_params)

  1. Or maybe i need define the TLogicRpc_StParams class in Python
class TLogicRpc_ServerParams:
    def __init__(self, serverId, status, sslEnable):
        self.destAddr = serverId
        self.destPort = status
        self.sslEnable = sslEnable
class TLogicRpc_ConnParams:
    def __init__(self, connId, venId):
        self.connId = connId
        self.venId = venId
class TLogicRpc_PostParams:
    def __init__(self, postId, vendorId, conn, server):
        self.postId = postId
        self.venId = venId
        self.conn = conn
        self.server = server
class TLogicRpc_StParams:
    def __init__(self, cPVendor, cPModel, posts, server):
        self.cPVendor = cPVendor
        self.cPModel = cPModel
        self.posts = posts
        self.server = server
conn = []
conn.append(TLogicRpc_ConnParams(1, "1"))
conn.append(TLogicRpc_ConnParams(2, "2"))
srv = TLogicRpc_ServerParams(1, 2, True)
post_params = TLogicRpc_PostParams(123, '123', conn, srv)
st_params = TLogicRpc_StParams("Vendor", "Model", post_params, srv)
client.call("method_name", st_params)

Does anyone have any idea how to implement it correctly?

Kirill R.
  • 1
  • 2

0 Answers0