|
Hi, everyone
I'm using qpid to transfer binary data. I find that Variant is designed for this purpose. But I also find that it only can serialize character string. I wonder if there is straight way to serialize byte stream. By the way, Is there complete API reference available? The documents I find are just tutorial and I wonder if I can learn more APIs or details about qpid from somewhere. --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
Hi,
The http://qpid.apache.org/books/0.14/Programming-In-Apache-Qpid/html/index.html guide describes what you are trying to do. Take a look at the the ::List type. As implemented by Qpid the List type maps an array into a single AMQP message object. For example you can send a single int in a message and the AMQP encoding will be <int:value>. Or you can send an array of int as a list encoded as <list: type=int, size=n, value, value, value...>. Using this strategy is a good idea as your receiver will receive the array without any explicit packing, unpacking, or byte swapping. Again, the Programming-In document describes this. You can deal with messages using raw bytes as easily as with using strings. See paste from Message.h below. With this method you can send arbitrary blocks of binary data no problem. Regards, Chuck /** * Set the content to the data held in the string parameter. Note: * this is treated as raw bytes and need not be text. Consider * setting the content-type to indicate how the data should be * interpreted by recipients. */ QPID_MESSAGING_EXTERN void setContent(const std::string&); /** * Copy count bytes from the region pointed to by chars as the * message content. */ QPID_MESSAGING_EXTERN void setContent(const char* chars, size_t count); /** Get the content as a std::string */ QPID_MESSAGING_EXTERN std::string getContent() const; /** * Get a const pointer to the start of the content data. The * memory pointed to is owned by the message. The getContentSize() * method indicates how much data there is (i.e. the extent of the * memory region pointed to by the return value of this method). */ QPID_MESSAGING_EXTERN const char* getContentPtr() const; /** Get the size of content in bytes. */ QPID_MESSAGING_EXTERN size_t getContentSize() const; ----- Original Message ----- > From: "Zhihua Che" <[hidden email]> > To: "users" <[hidden email]> > Sent: Sunday, April 1, 2012 6:10:37 AM > Subject: Is there compelte API reference and How serialize byte array like int array[n] > > Hi, everyone > > I'm using qpid to transfer binary data. I find that Variant is > designed for this purpose. But I also find that it only can serialize > character string. > I wonder if there is straight way to serialize byte stream. > > By the way, Is there complete API reference available? The > documents I find are just tutorial and I wonder if I can learn more > APIs or details about qpid from somewhere. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
Sorry, I'm late. First, thanks for your reply.
As far as portablity is concerned, I guess setContent(const char *, size_t) is not a suitable option. If I choose Variant, that means I have to write code like this: struct binary_data { int id; char name[8]; struct othertype filed; * * } __attribute__((aligned(sizeof(VAR_INT32)))); // sender struct binary_data data; Variant::list list; list.push_back(data.id); list.push_back(data.name); for (int i = 0, *p = (int*)&data.field; i < sizeof(data.field)/sizeof(VAR_INT32); i++) { list.push_back(*(p + i)); } // receiver struct binary_data data; data.id = list.pop_front(); // wrong grammer, but I believe you understand what I mean:-) data.name = list.pop_front(); for (int i = 0, *p = (int*)&data.filed; i < sizeof(data.field)/sizeof(VAR_INT32) ; i++) { *(p + i) = list.pop_front(); } It's a little wierd:-) I wonder if my code is a good programming style. 在 2012年4月1日 下午10:15,Chuck Rolke <[hidden email]> 写道: > Hi, > > The http://qpid.apache.org/books/0.14/Programming-In-Apache-Qpid/html/index.html guide describes what you are trying to do. Take a look at the the ::List type. As implemented by Qpid the List type maps an array into a single AMQP message object. For example you can send a single int in a message and the AMQP encoding will be <int:value>. Or you can send an array of int as a list encoded as <list: type=int, size=n, value, value, value...>. Using this strategy is a good idea as your receiver will receive the array without any explicit packing, unpacking, or byte swapping. Again, the Programming-In document describes this. > > You can deal with messages using raw bytes as easily as with using strings. See paste from Message.h below. With this method you can send arbitrary blocks of binary data no problem. > > Regards, > Chuck > > > /** > * Set the content to the data held in the string parameter. Note: > * this is treated as raw bytes and need not be text. Consider > * setting the content-type to indicate how the data should be > * interpreted by recipients. > */ > QPID_MESSAGING_EXTERN void setContent(const std::string&); > /** > * Copy count bytes from the region pointed to by chars as the > * message content. > */ > QPID_MESSAGING_EXTERN void setContent(const char* chars, size_t count); > > /** Get the content as a std::string */ > QPID_MESSAGING_EXTERN std::string getContent() const; > /** > * Get a const pointer to the start of the content data. The > * memory pointed to is owned by the message. The getContentSize() > * method indicates how much data there is (i.e. the extent of the > * memory region pointed to by the return value of this method). > */ > QPID_MESSAGING_EXTERN const char* getContentPtr() const; > /** Get the size of content in bytes. */ > QPID_MESSAGING_EXTERN size_t getContentSize() const; > > > > ----- Original Message ----- >> From: "Zhihua Che" <[hidden email]> >> To: "users" <[hidden email]> >> Sent: Sunday, April 1, 2012 6:10:37 AM >> Subject: Is there compelte API reference and How serialize byte array like int array[n] >> >> Hi, everyone >> >> I'm using qpid to transfer binary data. I find that Variant is >> designed for this purpose. But I also find that it only can serialize >> character string. >> I wonder if there is straight way to serialize byte stream. >> >> By the way, Is there complete API reference available? The >> documents I find are just tutorial and I wonder if I can learn more >> APIs or details about qpid from somewhere. >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [hidden email] >> For additional commands, e-mail: [hidden email] >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
|
On 04/05/2012 03:39 AM, Zhihua Che wrote:
> Sorry, I'm late. First, thanks for your reply. > > As far as portablity is concerned, I guess setContent(const char *, > size_t) is not a suitable option. For a simple byte array, that would be fine. However if that byte array actually represents some more complex structure then you are right, it would likely be non-portable. However the solution to that is not to encode a byte array, but to encode the fields of the structure recursively in explicit types. Btw Variant can encode raw binary data (i.e. byte arrays), not just character strings. At present you have to do this either with a std::string (does not imply text only) or with a c-style, null terminated string. Adding a method to allow you to use a char* and a size would be a reasonable enhancement. > If I choose Variant, that means I have to write code like this: > > struct binary_data > { > int id; > char name[8]; > struct othertype filed; > * > * > } __attribute__((aligned(sizeof(VAR_INT32)))); > > // sender > struct binary_data data; > Variant::list list; > list.push_back(data.id); > list.push_back(data.name); > for (int i = 0, *p = (int*)&data.field; i< > sizeof(data.field)/sizeof(VAR_INT32); i++) > { > list.push_back(*(p + i)); > } I don't think this is portable either. Your alignment attribute wouldn't prevent problems from different endianness would it? > // receiver > struct binary_data data; > data.id = list.pop_front(); // wrong grammer, but I believe you > understand what I mean:-) > data.name = list.pop_front(); > for (int i = 0, *p = (int*)&data.filed; i< > sizeof(data.field)/sizeof(VAR_INT32) ; i++) > { > *(p + i) = list.pop_front(); > } > > It's a little wierd:-) > > I wonder if my code is a good programming style. > > 在 2012年4月1日 下午10:15,Chuck Rolke<[hidden email]> 写道: >> Hi, >> >> The http://qpid.apache.org/books/0.14/Programming-In-Apache-Qpid/html/index.html guide describes what you are trying to do. Take a look at the the ::List type. As implemented by Qpid the List type maps an array into a single AMQP message object. For example you can send a single int in a message and the AMQP encoding will be<int:value>. Or you can send an array of int as a list encoded as<list: type=int, size=n, value, value, value...>. Using this strategy is a good idea as your receiver will receive the array without any explicit packing, unpacking, or byte swapping. Again, the Programming-In document describes this. >> >> You can deal with messages using raw bytes as easily as with using strings. See paste from Message.h below. With this method you can send arbitrary blocks of binary data no problem. >> >> Regards, >> Chuck >> >> >> /** >> * Set the content to the data held in the string parameter. Note: >> * this is treated as raw bytes and need not be text. Consider >> * setting the content-type to indicate how the data should be >> * interpreted by recipients. >> */ >> QPID_MESSAGING_EXTERN void setContent(const std::string&); >> /** >> * Copy count bytes from the region pointed to by chars as the >> * message content. >> */ >> QPID_MESSAGING_EXTERN void setContent(const char* chars, size_t count); >> >> /** Get the content as a std::string */ >> QPID_MESSAGING_EXTERN std::string getContent() const; >> /** >> * Get a const pointer to the start of the content data. The >> * memory pointed to is owned by the message. The getContentSize() >> * method indicates how much data there is (i.e. the extent of the >> * memory region pointed to by the return value of this method). >> */ >> QPID_MESSAGING_EXTERN const char* getContentPtr() const; >> /** Get the size of content in bytes. */ >> QPID_MESSAGING_EXTERN size_t getContentSize() const; >> >> >> >> ----- Original Message ----- >>> From: "Zhihua Che"<[hidden email]> >>> To: "users"<[hidden email]> >>> Sent: Sunday, April 1, 2012 6:10:37 AM >>> Subject: Is there compelte API reference and How serialize byte array like int array[n] >>> >>> Hi, everyone >>> >>> I'm using qpid to transfer binary data. I find that Variant is >>> designed for this purpose. But I also find that it only can serialize >>> character string. >>> I wonder if there is straight way to serialize byte stream. >>> >>> By the way, Is there complete API reference available? The >>> documents I find are just tutorial and I wonder if I can learn more >>> APIs or details about qpid from somewhere. >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [hidden email] >>> For additional commands, e-mail: [hidden email] >>> >>> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [hidden email] >> For additional commands, e-mail: [hidden email] >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [hidden email] > For additional commands, e-mail: [hidden email] > --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
| Powered by Nabble | Edit this page |
