Re: map values in message body

2014-05-19 Thread Rafael Schloming
This mysterious incarnation seems to be able to tell the difference:

  sub isnum ($) {
  return 0 if $_[0] eq '';
  $_[0] ^ $_[0] ? 0 : 1
  }

If you want to know why then have a look at this thread:


http://www.perlmonks.org/?node=How%20to%20check%20if%20a%20scalar%20value%20is%20numeric%20or%20string%3F

My brief and cynical summary is that the general perl philosophy is that
there is no difference between 'strings that look like numbers' and
'numbers', however seeing how perl is a bastion of inconsistency, there is
sometimes a difference so it's sometimes important what kind of value you
have, and the above code uses some of those differences to detect what kind
scalar is supplied.

--Rafael



On Fri, May 16, 2014 at 4:46 PM, Darryl L. Pierce dpie...@redhat.comwrote:

 On Thu, May 15, 2014 at 01:04:13PM -0400, Ernest Allen wrote:
  Does proton messenger support sending complex maps as the message body?
 That is, maps whose values are other maps or lists and not just strings?
 
  When I send a message and the body is encoded as qpid::proton::MAP, the
 map values appear to have been converted to strings.
 
  For example (in perl)
 
  In the sender
  $msg-set_body({foo = 2, bar = [3]}, qpid::proton::MAP);
 
  In the receiver when I dump the body, I'm getting
   $VAR1 = \{
  'bar' = 'ARRAY(0xa2aad0)',
  'foo' = '2'
};
 
  It appears that the array has been converted to the string
 'ARRAY(0x...)'. And the 2 is now a string '2'.
  I don't think this is just the way the receiver is dumping the message
 body as I'm not able to convert the results to the expected type or
 variable.
 
  When I send a perl HASH instead of an array as one of the values, it is
 coming through as the string'HASH(0x)'.

 This should now be fixed on trunk. I've updated the recv.pl example to
 display the full body of received messages to verify that all values are
 being passed.

 Now, that being said, there's a caveat with Perl. Since there's no way
 for Perl to determine what any scalar value is (beyond the class name
 for blessed objects) everything has to be inserted into the data object
 as a string. So, for example, if you put the following into the body of
 a message in Perl:

   $msg-set_body({fibonacci = [1, 1, 2, 3, 5, 8, 13]});

 then the receive will get:

   {fibonacci = [1, 1, 2, 3, 5, 8, 13]}

 I'll continue to look for some way to improve this, but for now at least
 the structure of complex hashes and arrays are preserved in Perl.

 --
 Darryl L. Pierce, Sr. Software Engineer @ Red Hat, Inc.
 Delivering value year after year.
 Red Hat ranks #1 in value among software vendors.
 http://www.redhat.com/promo/vendor/




map values in message body

2014-05-16 Thread Ernest Allen
Does proton messenger support sending complex maps as the message body? That 
is, maps whose values are other maps or lists and not just strings?

When I send a message and the body is encoded as qpid::proton::MAP, the map 
values appear to have been converted to strings.

For example (in perl)

In the sender
$msg-set_body({foo = 2, bar = [3]}, qpid::proton::MAP);

In the receiver when I dump the body, I'm getting
 $VAR1 = \{
'bar' = 'ARRAY(0xa2aad0)',
'foo' = '2'
  };

It appears that the array has been converted to the string 'ARRAY(0x...)'. And 
the 2 is now a string '2'.
I don't think this is just the way the receiver is dumping the message body as 
I'm not able to convert the results to the expected type or variable.

When I send a perl HASH instead of an array as one of the values, it is coming 
through as the string'HASH(0x)'. 

-Ernie


Re: map values in message body

2014-05-16 Thread Rafael Schloming
That's most definitely a bug in the Perl binding. It should properly
introspect the types of keys/values just like the other bindings. If you
file a JIRA I'll see what I can do about fixing it or poking someone else
to fix it. ;-)

--Rafael


On Fri, May 16, 2014 at 11:45 AM, Fraser Adams 
fraser.ad...@blueyonder.co.uk wrote:

 Hi Ernie,
 Messenger per se certainly supports this, the python binding introspects
 the types accurately and I'm currently writing unit tests for my JavaScript
 port to prove test the JavaScript introspection behaves correctly too, so
 if you are seeing an issue it'll be with the Perl binding and not with the
 underlying Messenger.

 Unfortunately I don't know Perl especially well so I can't help much other
 than to suggest that you take a look in the files
 proton/proton-c/bindings/perl/lib/qpid/proton/Message.pm
 proton/proton-c/bindings/perl/lib/qpid/proton/Data.pm

 The most likely place you want to look is the method preencode() in
 Message.pm, when you call $messenger-put() it'll call
 $message-preencode();

 Inside preencode() it's calling

 $body_type-put($body, $my_body) if($my_body  $body_type);

 which (I think form the following code in Constants.pm
 MAP  = qpid::proton::Mapping-new(
 map,
 $cproton_perl::PN_MAP,
 put_map_helper,
 get_map_helper),
 )

 results in put_map_helper in Data.pm getting called

 - aha!! having just shown my working I see the following:

 sub put_map_helper {
 my ($self) = @_;
 my ($hash) = $_[1];

 $self-put_map;
 $self-enter;

 foreach(keys $hash) {
 $self-put_string($_);
 $self-put_string($hash-{$_});
 }

 $self-exit;
 }


 I guess that the
 $self-put_string($_);
 $self-put_string($hash-{$_});

 are the culprits, so it looks like the Perl binding is indeed putting
 string values for the AMQP Map values.

 So I'm afraid my long answer to you short question appears to be that
 Messenger per se does not have the limitation you observe, but it looks
 like the Perl binding does (if my interpretation of the code is correct) :-(

 Frase



 On 15/05/14 18:04, Ernest Allen wrote:

 Does proton messenger support sending complex maps as the message body?
 That is, maps whose values are other maps or lists and not just strings?

 When I send a message and the body is encoded as qpid::proton::MAP, the
 map values appear to have been converted to strings.

 For example (in perl)

 In the sender
 $msg-set_body({foo = 2, bar = [3]}, qpid::proton::MAP);

 In the receiver when I dump the body, I'm getting
   $VAR1 = \{
  'bar' = 'ARRAY(0xa2aad0)',
  'foo' = '2'
};

 It appears that the array has been converted to the string
 'ARRAY(0x...)'. And the 2 is now a string '2'.
 I don't think this is just the way the receiver is dumping the message
 body as I'm not able to convert the results to the expected type or
 variable.

 When I send a perl HASH instead of an array as one of the values, it is
 coming through as the string'HASH(0x)'.

 -Ernie





Re: map values in message body

2014-05-16 Thread Darryl L. Pierce
On Thu, May 15, 2014 at 01:04:13PM -0400, Ernest Allen wrote:
 Does proton messenger support sending complex maps as the message body? That 
 is, maps whose values are other maps or lists and not just strings?
 
 When I send a message and the body is encoded as qpid::proton::MAP, the map 
 values appear to have been converted to strings.
 
 For example (in perl)
 
 In the sender
 $msg-set_body({foo = 2, bar = [3]}, qpid::proton::MAP);
 
 In the receiver when I dump the body, I'm getting
  $VAR1 = \{
 'bar' = 'ARRAY(0xa2aad0)',
 'foo' = '2'
   };
 
 It appears that the array has been converted to the string 'ARRAY(0x...)'. 
 And the 2 is now a string '2'.
 I don't think this is just the way the receiver is dumping the message body 
 as I'm not able to convert the results to the expected type or variable.
 
 When I send a perl HASH instead of an array as one of the values, it is 
 coming through as the string'HASH(0x)'. 

This should now be fixed on trunk. I've updated the recv.pl example to
display the full body of received messages to verify that all values are
being passed.

Now, that being said, there's a caveat with Perl. Since there's no way
for Perl to determine what any scalar value is (beyond the class name
for blessed objects) everything has to be inserted into the data object
as a string. So, for example, if you put the following into the body of
a message in Perl:

  $msg-set_body({fibonacci = [1, 1, 2, 3, 5, 8, 13]});

then the receive will get:

  {fibonacci = [1, 1, 2, 3, 5, 8, 13]}

I'll continue to look for some way to improve this, but for now at least
the structure of complex hashes and arrays are preserved in Perl.

-- 
Darryl L. Pierce, Sr. Software Engineer @ Red Hat, Inc.
Delivering value year after year.
Red Hat ranks #1 in value among software vendors.
http://www.redhat.com/promo/vendor/



pgpalvNfYs_43.pgp
Description: PGP signature


Re: map values in message body

2014-05-16 Thread Fraser Adams

Hi Ernie,
Messenger per se certainly supports this, the python binding introspects 
the types accurately and I'm currently writing unit tests for my 
JavaScript port to prove test the JavaScript introspection behaves 
correctly too, so if you are seeing an issue it'll be with the Perl 
binding and not with the underlying Messenger.


Unfortunately I don't know Perl especially well so I can't help much 
other than to suggest that you take a look in the files

proton/proton-c/bindings/perl/lib/qpid/proton/Message.pm
proton/proton-c/bindings/perl/lib/qpid/proton/Data.pm

The most likely place you want to look is the method preencode() in 
Message.pm, when you call $messenger-put() it'll call 
$message-preencode();


Inside preencode() it's calling

$body_type-put($body, $my_body) if($my_body  $body_type);

which (I think form the following code in Constants.pm
MAP  = qpid::proton::Mapping-new(
map,
$cproton_perl::PN_MAP,
put_map_helper,
get_map_helper),
)

results in put_map_helper in Data.pm getting called

- aha!! having just shown my working I see the following:

sub put_map_helper {
my ($self) = @_;
my ($hash) = $_[1];

$self-put_map;
$self-enter;

foreach(keys $hash) {
$self-put_string($_);
$self-put_string($hash-{$_});
}

$self-exit;
}


I guess that the
$self-put_string($_);
$self-put_string($hash-{$_});

are the culprits, so it looks like the Perl binding is indeed putting 
string values for the AMQP Map values.


So I'm afraid my long answer to you short question appears to be that 
Messenger per se does not have the limitation you observe, but it looks 
like the Perl binding does (if my interpretation of the code is correct) :-(


Frase


On 15/05/14 18:04, Ernest Allen wrote:

Does proton messenger support sending complex maps as the message body? That 
is, maps whose values are other maps or lists and not just strings?

When I send a message and the body is encoded as qpid::proton::MAP, the map 
values appear to have been converted to strings.

For example (in perl)

In the sender
$msg-set_body({foo = 2, bar = [3]}, qpid::proton::MAP);

In the receiver when I dump the body, I'm getting
  $VAR1 = \{
 'bar' = 'ARRAY(0xa2aad0)',
 'foo' = '2'
   };

It appears that the array has been converted to the string 'ARRAY(0x...)'. And 
the 2 is now a string '2'.
I don't think this is just the way the receiver is dumping the message body as 
I'm not able to convert the results to the expected type or variable.

When I send a perl HASH instead of an array as one of the values, it is coming 
through as the string'HASH(0x)'.

-Ernie