qpid-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rafael Schloming <rafa...@redhat.com>
Subject Re: Maps (cross-language)
Date Sat, 19 Jul 2008 01:14:26 GMT
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);
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.


View raw message