msgpack/msgpack-python

Option to parse first object only and ignore extra bytes

kjsdf7wr3 opened this issue · 1 comments

Is it possible to add an option to stop parsing after first complete object and ignore extra bytes?

Raises ``ExtraData`` when *packed* contains extra bytes.

In an appliction I receive data that is padded and currently I remove bytes at the end until there is no more ExtraData exception.
For me it is impossible to know the amount of padding bytes, except that they occur after the first complete object/value.

You can get object and remaining data from ExtraData.

class ExtraData(UnpackValueError):
"""ExtraData is raised when there is trailing data.
This exception is raised while only one-shot (not streaming)
unpack.
"""
def __init__(self, unpacked, extra):
self.unpacked = unpacked
self.extra = extra