On Thu, 2018-03-15 at 15:54 -0400, Kim van der Riet wrote:
> When creating an AMQP map body, using
> 
> std::map<proton::value, proton::value> map;
> 
> to represent the map, and once its values have been set,
> 
> proton::message msg;
> msg.body(map);
> 
> is a convenient way to set the message body. However, in practice, I
> am 
> finding this approach has one problem - I cannot guarantee the
> key/value 
> ordering within the map.

Why do want to do this?

> 
> On the receiving end, if I don't know the map keys in advance, I need
> to 
> use a similar approach:
> 
> std::map<proton::value, proton::value> map;
> proton::get(msg.body(), map);
> 
> which puts the map into a std::map where I can iterate through keys, 
> etc. But as soon as I do this, I have lost the ordering guarantees
> of 
> the original message, as the map will iterate through the keys in an 
> internal order unrelated to the message ordering.
> 
> What is the correct way to both set a proton::value as a map in such
> a 
> way that the ordering is preserved when I both set the values and
> read 
> them afterward without knowledge of the keys?

I'm not sure what you are trying to accomplish, perhaps you can explain
 and that would make this easier to answer.

Essentially though the AMQP concept of a map and language binding
concepts of maps differ.

They are just the closest most convenient things that allow users to
accomplish what they most likely want to accomplish: That is to send an
application level map/dictionary and receive it in a perhaps different
language environment with the same meaning (more-or-less).

As it happens std::map actually does have a well defined order (it is
always ordered by the "less-than" relation on its keys) and I believe
that the Qpid C++ binding coder will transcribe that into the AMQP map
- this is not one of our tests though so it is entirely possible the
iterator used goes backwards instead!

However the map binding in other languages is much more likely to use
the hash of the keys in the data structure and so there will be no well
defined order for them.

There are other "features" of AMQP maps that just aren't directly
transcribeable to language features - especially if there are repeated
identical keys in an AMQP map.

Hope that helps

Andrew


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@qpid.apache.org
For additional commands, e-mail: users-h...@qpid.apache.org

Reply via email to