You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tl;dr: It would be nice if Payload() consumed data until the first None/null-character if no length is specified, rather than the last instance of it as it appears to currently be doing.
I'm running into a problem with a Structure containing two null-delimited strings. The protocol doesn't specify information about the length of these strings. I wrote my own protocol parser before discovery this library, so I already have the protocol broken down into logical segments/Structures, but I was hoping to get rid of my hack job in favour of using Suitcase to parse the individual fields.
Reading the docs, I see this is probably an explanation for my situation:
Parameters: length_provider – The LengthField with which this variable length payload is associated. If not included, it is assumed that the length_provider should consume the remainder of the bytes available in the string. This is only valid in cases where the developer knows that they will be dealing with a fixed sequence of bytes (already boxed).
What would be the best way to work within the framework with such a constraint? Is there any way to make Payload() be lazy rather than greedy?
In [1]: import success
In [2]: s = success.Header()
In [3]: s.unpack(b'\x00\x00\x007\n123.45.67.89-8888\x00Some-String-2\x00\x00\x00\x01Z\xa5\xfb\xc8\xab\x00\x0e\x00\x15\x00\x01\x00\x00')
In [4]: s
Out[4]:
Header (
a=55,
b=10,
c=b'123.45.67.89-8888\x00Some-String-2\x00',
e=1488843425963,
f=14,
g=21,
h=1,
i=0,
)
In [1]: importfailureIn [2]: f=failure.Header()
In [3]: f.unpack(b'\x00\x00\x007\n123.45.67.89-8888\x00Some-String-2\x00\x00\x00\x01Z\xa5\xfb\xc8\xab\x00\x0e\x00\x15\x00\x01\x00\x00')
---------------------------------------------------------------------------SuitcaseParseErrorTraceback (mostrecentcalllast)
<ipython-input-3-91ea443f72a0>in<module>()
---->1f.unpack(b'\x00\x00\x007\n123.45.67.89-8888\x00Some-String-2\x00\x00\x00\x01Z\xa5\xfb\xc8\xab\x00\x0e\x00\x15\x00\x01\x00\x00')
/home/mpelikan/.local/lib/python3.6/site-packages/suitcase/structure.pyinunpack(self, data, trailing)
339340defunpack(self, data, trailing=False):
-->341returnself._packer.unpack(data, trailing)
342343defpack(self):
/home/mpelikan/.local/lib/python3.6/site-packages/suitcase/structure.pyinunpack(self, data, trailing)
62defunpack(self, data, trailing=False):
63stream=BytesIO(data)
--->64self.unpack_stream(stream)
65stream.tell()
66iftrailing:
/home/mpelikan/.local/lib/python3.6/site-packages/suitcase/structure.pyinunpack_stream(self, stream)
150"%r we tried to read %s bytes but "151"we were only able to read %s."%-->152 (_name, length, len(data)))
153try:
154field.unpack(data)
SuitcaseParseError: Whileattemptingtoparsefield'd'wetriedtoreadNonebytesbutwewereonlyabletoread32.
The text was updated successfully, but these errors were encountered:
martinpelikan
changed the title
Structure fails with 2+ null-delimited strings.
Structure fails with 2+ unknown-length, null-delimited strings.
Mar 7, 2017
Since the two strings in my case are found in succession and can be read out by the same Payload() field, I've used a bit of a hack to work around this for now.
I looked through the closed Issues and PRs, and noticed a similar request here: #21. In my case all of this data is within a fixed frame, but there are two unknown size Payload() fields, whereas in the case one of them is constrained to a fixed size which is what probably makes the test work...
martinpelikan
changed the title
Structure fails with 2+ unknown-length, null-delimited strings.
Support for variable-length, non-greedy Payload()
Mar 15, 2017
tl;dr: It would be nice if Payload() consumed data until the first None/null-character if no length is specified, rather than the last instance of it as it appears to currently be doing.
I'm running into a problem with a
Structure
containing two null-delimited strings. The protocol doesn't specify information about the length of these strings. I wrote my own protocol parser before discovery this library, so I already have the protocol broken down into logical segments/Structures, but I was hoping to get rid of my hack job in favour of using Suitcase to parse the individual fields.Reading the docs, I see this is probably an explanation for my situation:
What would be the best way to work within the framework with such a constraint? Is there any way to make
Payload()
be lazy rather than greedy?success.py
:Success output:
failure.py
:Failure output:
The text was updated successfully, but these errors were encountered: