You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by Joe Ly <jo...@mikelinc.com> on 2012/10/18 21:33:17 UTC
Try to send a user-defined struct using C++ QPID
Hi,
Anyone knows how I could send a C/C++ user-defined struct that encodes into qpid messages?
For example, my struct is defined as
struct a {
int j;
float k;
float r[29];
} a;
Thanks,
Joe Ly
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org
RE: Try to send a user-defined struct using C++ QPID
Posted by Joe Ly <jo...@mikelinc.com>.
For the first case,
if I use a Variant::Map, after I received and decoded the message to get my struct, how could I extract Variant::List and Variant::Map correctly?
Example:
//sender
Message message;
Variant::Map content;
content["id"] = 987654321; //int
content["name"] = "Widget";//string
content["percent"] = 0.99; //double
Variant::List colours;
colours.push_back(Variant("red"));
colours.push_back(Variant("green"));
colours.push_back(Variant("white"));
content["colours"] = colours;
Variant::Map dimensions;
dimensions["length"] = 10.2;
dimensions["width"] = 5.1;
dimensions["depth"] = 2.0;
content["dimensions"]= dimensions;
encode(content, message);
sender.send(message, true);
//receiver
Message message_receive = receiver.fetch(Duration::SECOND * 1);
Variant::Map content1;
decode(message_receive, content1);
//extract contents from received message
int identification = content1["id"];
string name1 = content1["name"];
double percent1 = content1["percent"];
???Variant::List colours_received = content["colours"]; ??? (Is this right?)
???Variant::Map dimensions_received = content["dimensions"]; ???
Thanks,
Joe Ly
________________________________________
From: Andy Goldstein [andy.goldstein@redhat.com]
Sent: Thursday, October 18, 2012 3:38 PM
To: users@qpid.apache.org
Subject: Re: Try to send a user-defined struct using C++ QPID
Hi Joe,
You have a couple of tried & true options. You could manually copy the data from the struct into a Variant::Map and encode that into a Message. You could use a library such as Google Protocol Buffers to both store the data in memory (i.e. instead of using a struct you'd use a protobuf generated class) and for transmission across the wire (since it serializes to/from a string).
Hope this helps,
Andy
On Oct 18, 2012, at 3:33 PM, Joe Ly wrote:
> Hi,
>
> Anyone knows how I could send a C/C++ user-defined struct that encodes into qpid messages?
>
> For example, my struct is defined as
>
> struct a {
> int j;
> float k;
> float r[29];
> } a;
>
>
> Thanks,
>
>
> Joe Ly
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org
Re: Try to send a user-defined struct using C++ QPID
Posted by Andy Goldstein <an...@redhat.com>.
Hi Joe,
You have a couple of tried & true options. You could manually copy the data from the struct into a Variant::Map and encode that into a Message. You could use a library such as Google Protocol Buffers to both store the data in memory (i.e. instead of using a struct you'd use a protobuf generated class) and for transmission across the wire (since it serializes to/from a string).
Hope this helps,
Andy
On Oct 18, 2012, at 3:33 PM, Joe Ly wrote:
> Hi,
>
> Anyone knows how I could send a C/C++ user-defined struct that encodes into qpid messages?
>
> For example, my struct is defined as
>
> struct a {
> int j;
> float k;
> float r[29];
> } a;
>
>
> Thanks,
>
>
> Joe Ly
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
> For additional commands, e-mail: users-help@qpid.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@qpid.apache.org
For additional commands, e-mail: users-help@qpid.apache.org