You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by Jonathan Robie <jo...@redhat.com> on 2008/07/17 23:51:33 UTC
Maps (cross-language)
Suppose I have clients in Java JMS, Python, and C++, and they need to
exchange maps.
Is there currently a good way to do this? I can't quite see how.
Jonathan
Re: Maps (cross-language)
Posted by Rafael Schloming <ra...@redhat.com>.
Ted Ross wrote:
> Jonathan Robie wrote:
>> Suppose I have clients in Java JMS, Python, and C++, and they need to
>> exchange maps.
>>
>> Is there currently a good way to do this? I can't quite see how.
>>
>> Jonathan
> There are ways to do this in each language. It's very easy in Python as
> maps are represented as dictionaries. The Codec class is used to encode
> and decode the various AMQP types.
>
> In C++, the Buffer class can be used to encode and decode a subset of
> the AMQP types. The FieldTable class implements maps. For the C++
> client, there is a non-obvious conversion from string to Buffer that is
> needed in order to encode/decode AMQP types in message bodies.
>
> In Java, there is an encoder/decoder, the details of which you will need
> to get from someone else.
Right now you would convert a Map to a ByteBuffer as follows in Java:
BBEncoder enc = new BBEncoder(initialCapacity);
enc.init();
enc.writeMap(map);
ByteBuffer buf = enc.done();
Realistically you'd probably want to reuse the BBEncoder object since it
caches various conversions, e.g. stick it in a ThreadLocal or something.
One warning though, the above code is used by one of the most
performance sensitive pieces of the client, so it is somewhat subject to
change based on profiling.
I think it would probably be nicer and a bit safer from an API
perspective to provide a slightly more convenient way to access this
functionality, e.g. maybe some kind of message object you could
construct that would have the appropriate write/read methods for the
various types that AMQP defines encoding for.
--Rafael
Re: Maps (cross-language)
Posted by Ted Ross <tr...@redhat.com>.
Jonathan Robie wrote:
> Suppose I have clients in Java JMS, Python, and C++, and they need to
> exchange maps.
>
> Is there currently a good way to do this? I can't quite see how.
>
> Jonathan
There are ways to do this in each language. It's very easy in Python as
maps are represented as dictionaries. The Codec class is used to encode
and decode the various AMQP types.
In C++, the Buffer class can be used to encode and decode a subset of
the AMQP types. The FieldTable class implements maps. For the C++
client, there is a non-obvious conversion from string to Buffer that is
needed in order to encode/decode AMQP types in message bodies.
In Java, there is an encoder/decoder, the details of which you will need
to get from someone else.
If it's helpful, I can supply examples in both Python and C++.
-Ted