How should I write the 'signature' in this case ?

asked 2014-12-14 18:33:17 -0700

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

I have the following data structure, and define a object of this type:thisdev

I want to encapsulate thisdev into a message arg,then how should I write the 'signature' of this type ?

It seems that I cannot find the code of type:enum and union

MsgArg arg;
arg.Set("(unknown ???)",thisdev);

That is :I don't know how to write the "unknown ???" part.. Please help!

the following is the definition of 'thisdev':

 enum res_type{

union res_value
    double dataval;
    bool swval;
    char* imgval;

struct res_info {
    res_type restype;   
    res_value resval;

struct dev_info{
    const char* dev_ip;
    uint8_t rescount;
    struct res_info res;

thisdev.dev_ip = "";

thisdev.rescount = 2;

thisdev.res.restype = DATA_SENSOR;

thisdev.res.resval.dataval = 25.0;
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2014-12-16 15:29:26 -0700

georgen gravatar image

updated 2014-12-19 08:08:38 -0700

You need to break the thisdev down into its internal data.

  • dev_ip is a string so s
  • rescount is a byte so y
  • res_info is a struct so ( contents of resinfo )
    • res_tpe is a enum this can be converted to a string or an integer that is up to you lets use an integer i for this example
    • resval is a union so use a variant v

taking all that into account you will have a signature as follows:


MsgArg arg;
MsgArg arg_res_val;
MsgArg arg_dataval.Set("d", thisdev.res.resval.dataval);
MsgArg arg_swval.Set("b", thisdev.res.resval.swval);
MsgArg arg_imgval.Set("s", thisdev.res.resval.imgval);
// You have to know what is being used in the union
MsgArg arg_es_val;
if (using_dataval) {
    arg_es_val.Set("v", arg_dataval);
} else if (using_swval) {
    arg_es_val.Set("v", arg_swval);
} else if (using_imgval) {
    arg_es_val.Set("v", arg_imgval);
status = arg.Set("(sy(iv))", thisdev.dev_ip, 

note you could also have broken it out of the initial struct:

signature "sy(iv)"

MsgArg args[3];
arg[0].Set("s", thisdev.dev_ip);
arg[1].Set("y", thisdev.rescount);
arg[2].Set("(iv)", (int)thisdev.res.restype, 
edit flag offensive delete publish link more


thank you so much. I will try this way .

Lewis ( 2014-12-18 17:14:09 -0700 )edit

@Lewis I wrote the code without looking at any documentation. It should work. However, if you are having problems let me know.

georgen ( 2014-12-19 08:12:31 -0700 )edit

If dev_info is the following structure,then what's signature ? is it '(syay)' ? but how should i call Set function, it seems that array element number should be a parameter of Set call I guess arg.Set("(syay)",thisdev) won't work. struct dev_info { char* dev_ip; uint8_t rescnt; uint8_t res[4]; };

Lewis ( 2014-12-22 06:28:18 -0700 )edit

arg.Set("(syay)", thisdev.dev_ip, thisdev.rescount, size_of_ayArray, pointer_to_start_ofayArray) sorry I don't know where you got the ay signature for the structure by looking at your source code so I don't have a better example.

georgen ( 2015-01-12 13:53:58 -0700 )edit

answered 2014-12-16 06:21:41 -0700

Enum and union are not types that are available (yet?) in signatures. As an alternative you could use an integer where enums are needed and a variant where a union is required.

edit flag offensive delete publish link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2014-12-14 18:33:17 -0700

Seen: 105 times

Last updated: Dec 19 '14