in reply to Re: unpack less than indicated length
in thread unpack less than indicated length
++ :)
For those who are staring at this in confusion like I did a few minutes ago, '.' returns (adds to the stack) the current position in bytes relative to the start of the current () group. This is obvious (knowing what '.' does in the pack case) now that I've seen it but I didn't understand it on my own.
So to explain how the second template works (the left part, the right part is basically the same except instead of moving right a lot and then left a little, it moves left a little then right at lot, to avoid moving out of the string):
If L is the length of the data (2 in the case of "Hi"), the second byte will contain the value L+2 (1 for the type byte, 1 for the length byte, and L for the data). So:
One of the things that puzzled me is why the number after X was twice the number of bytes in the header. With a N bytes long header, we first move N times by reading them, then move L+N bytes because the length includes N. So we are indeed at position L+2N
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: unpack less than indicated length
by AnomalousMonk (Archbishop) on Jun 04, 2018 at 14:36 UTC |