Besides the pack() function, one of the purpose of this code is trying to reduce the size of the binary file base on the nature of the data.
If the length of the value string is less than 255, you need 3 bytes (2 bytes for the id, and 1 byte for the length); else you need 5 bytes. You can pack the length with "s" regardless, in which case, you need 4 bytes every time. If the length is less than 255 for most of the time, your way obviously reduces the length of the binary file, otherwise it increases the length.
In reply to Re: Understanding pack syntax
by pg
in thread Understanding pack syntax
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |