Hi All,

I tried posting this earlier as well. I am having trouble with
deserializing a string when using protobuf 2.5 or 2.6 on python2.7. Since I
was getting exceptions during decoding I modified the source code
around *google/protobuf/internal/decoder.py”,
line 521, in DecodeField* to add some more debug information.

The issue happens when I am decoding after I have received the message
through another source (in my case RabbitMQ) but not when I use the same
python code to serialize and deserialize. However, I did check the hex code
and length of the strings in both the cases and the messages are exactly
the same.

Here’s the error in detail. It receives a size of 32 for a buffer of “
003652” starting at pos 90 as “ “ (space) is ascii 32. It seems like the
code starts thinking here in terms of numbers rather than string but hard
for me to say.

raise _DecodeError('----------- Truncated string. buffer[] = x{}x \n\t
new_pos={}; end={}; size={}; pos={}; \n
Locals={}'.format(buffer[pos:], new_pos, end, size, pos, locals()))
DecodeError: ----------- Truncated string. buffer[] = x33652x
 new_pos=123; end=96; size=32; pos=91;
 Locals={'key': <google.protobuf.descriptor.FieldDescriptor object at
0x7fb4b22b3e90>, 'end': 96, 'field_dict':
{<google.protobuf.descriptor.FieldDescriptor object at
0x7fb4b22b3d10>: <core_pb2.InstrumentId object at 0x7fb4ad148140>,
<google.protobuf.descriptor.FieldDescriptor object at 0x7fb4b22b3dd0>:
<mkt_pb2.MarketInfoL1 object at 0x7fb4ad1482a8>,
<google.protobuf.descriptor.FieldDescriptor object at 0x7fb4b22b3d50>:
<core_pb2.DateTime object at 0x7fb4ad148230>,
<google.protobuf.descriptor.FieldDescriptor object at 0x7fb4b22b3d90>:
1}, 'new_pos': 123L, 'buffer':
'\n\x1a\x08\x08\x12\x16FUTURE|XSES|NKZ15|1512\x12\x11\x08\xe6\xf5\xcd\t\x12\n\x08\xf6\x8a\x05\x10\xf0\xbb\x8e\xe6\x01\x18\x01"&\x08\x9c\x9e\r\x10\x01\x1a\x1a\x08\x08\x12\x16FUTURE|XSES|NKZ15|15122\x02\x10):
33652', 'pos': 91L, 'local_DecodeVarint': <function DecodeVarint at
0x7fb4b24c00c8>, 'message': <box_pb2.RawTick object at
0x7fb4ad146de8>, '_ConvertToUnicode': <function _ConvertToUnicode at
0x7fb4b23c2cf8>, 'size': 32L}

The code in decoder.py was changed as follows:

def DecodeField(buffer, pos, end, message, field_dict):
  print('++++++++++++++Truncated string. buffer[] = x{}x \n\t end={};
pos={}; \n Locals={}'.format(buffer, end, pos, locals()))
  (size, pos) = local_DecodeVarint(buffer, pos)
  # size = 1
  new_pos = pos + size
  if new_pos > end:
      raise _DecodeError('----------- Truncated string. buffer[] =
x{}x \n\t new_pos={}; end={}; size={}; pos={}; \n
Locals={}'.format(buffer[pos:], new_pos, end, size, pos, locals()))
  field_dict[key] = _ConvertToUnicode(buffer[pos:new_pos])
  return new_pos
return DecodeField

Any help will be greatly appreciated.
​

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to