qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Zhihua Che <zhihua....@gmail.com>
Subject Re: Is there compelte API reference and How serialize byte array like int array[n]
Date Thu, 05 Apr 2012 02:39:48 GMT
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 <crolke@redhat.com> 写道:
> 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" <zhihua.che@gmail.com>
>> To: "users" <users@qpid.apache.org>
>> 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: 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


Mime
View raw message