Skip to content

Commit

Permalink
Dump small strings as s type instead of S type.
Browse files Browse the repository at this point in the history
  • Loading branch information
thedrow committed Mar 13, 2019
1 parent beb3060 commit 6c62798
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion amqp/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,11 @@ def _write_item(v, write, bits, pack=pack,
None_t=None):
if isinstance(v, string_t):
v = v.encode('utf-8', 'surrogatepass')
write(pack('>cI', b'S', len(v)))
string_length = len(v)
if string_length > 255:
write(pack('>cI', b'S', string_length))
else:
write(pack('>cB', b's', string_length))
write(v)
elif isinstance(v, bytes):
write(pack('>cI', b'x', len(v)))
Expand Down

1 comment on commit 6c62798

@michaelklishin
Copy link

@michaelklishin michaelklishin commented on 6c62798 Mar 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this change is unaware of the ambiguity in the spec
that lead RabbitMQ developers to deviate from it.
From https://www.rabbitmq.com/amqp-0-9-1-errata.html:

A1, A2: Notice how the types CONFLICT here. In Qpid and Rabbit,
         's' means a signed 16-bit integer; in 0-9-1, it means a
         short string.

Please sign in to comment.