Menu

Sending arrays and structs with nesting.

Help
Anonymous
2003-03-20
2003-03-20
  • Anonymous

    Anonymous - 2003-03-20

    Thanks for a great library here.  My problem is that I need to be able to send complex types.  Arrays of structs that may have imbedded arrays of structs.  I.E. array->struct->array->struct.  I'm looking through XmlRpcValue and see that the underlying functionality is there,  but how do you build a XmlRpcValue as an array/struct and then fill it with values.  I.E. I need something along the following lines:

    XMLRPCauthInfo["Name"] = authInfo.Name;
    XMLRPCauthInfo["ID"] = authInfo.ID;
    XMLRPCauthInfo["groupLogin"] = authInfo.groupLogin;
    XMLRPCauthInfo["groupPassword"] = authInfo.groupPassword;

    XMLRPC.execute("Server.authorize", XMLRPCauthInfo, result);

    I'm taking XMLRPCauthInfo to be a map<string, XmlRpcValue> as defined in XmlRpcValue.

    Do I need to build things myself here?  Any help will be greatly appreciated.

     
    • Chris Morley

      Chris Morley - 2003-03-20

      You should be able to something similar to what you have above, but XMLRPCauthInfo should be an XmlRpcValue, not a map. Also, the arguments to an RPC must be an XmlRpcValue of type Array.

      XmlRpcValues are used more like variables in javascript for example than C++: the type of the value is determined by what you assign to it. So to make an int XmlRpcValue, you assign an int to it. If you use the [] operator with an int index, you are declaring that the value is an array type; similarly if the index is a string you have a struct.

      See the HelloClient.cpp and TestValues.cpp files in the test directory of the distribution for some examples.

      We can expand your code a little to show the relevant declarations and some features:

      XmlRpcValue XMLRPCauthInfo;  // A struct of id info
      XmlRpcValue args;   // The array of arguments to your RPC
      XmlRpcValue result;  // The result of the RPC

      // First build up the argument
      XMLRPCauthInfo["Name"] = authInfo.Name;  // Assuming authInfo.Name is some compatible type, eg, std::string
      XMLRPCauthInfo["ID"] = authInfo.ID;

      // You can nest values arbitrarily deeply. This code
      // adds an entry "Children" to the XMLRPCauthInfo struct
      // with the value being an array of structs.
      for (int i=0; i<authInfo.Children.size(); ++i)
        XMLRPCauthInfo["Children"][i]["Name"] = authInfo.Children[i].Name;

      // Put the argument in the args array:
      args[0] = XMLRPCauthInfo;
      XMLRPC.execute("Server.authorize",args,result);

       

Log in to post a comment.