The functions ending with _big_endian
or _little_endian
are faster than the ones
with explicit byte_order
argument:
Name | Run time | S. dev. | Warnings ---------------------------------- | -------- | ------- | -------- pack_signed_16_little_endian | 4 ns | 0 ns | unpack_signed_16_little_endian | 5 ns | 0 ns | pack_signed_32_int | 12 ns | 0 ns | unpack_signed_32_int | 12 ns | 0 ns | pack_signed_32_int_little_endian | 4 ns | 0 ns | unpack_signed_32_int_little_endian | 5 ns | 0 ns | M pack_signed_64_int | 21 ns | 0 ns | M unpack_signed_64_int | 21 ns | 0 ns | M pack_signed_64_little_endian | 8 ns | 0 ns | unpack_signed_64_little_endian | 9 ns | 0 ns | M
As with integers, floats can be be packed big endian or little endian, depending on the order in which the bytes of the float are layed out. There is nothing interesting going on computationally from a floating-point perspective; just laying out eight bytes in one order or the other.
The following functions operate on "fixed length tail padded strings", by which is meant a string possibly followed by some padding, such that the length of the string plus the length of the padding equals the fixed length.
Decode the fixed length tail padded string having length len
from buf
starting at
pos
. Return a string containing only the non-padding characters. The default
padding is '\x00'.
Encode and pack the given string as a tail padded fixed length string having length
len
. Place it in buf
starting at position pos
. If the length of the string is
less then len
pad it with the padding characters until its length is equal to len
.
If the string is longer than len
raise Invalid_argument
. The default padding is
'\x00'.