pack
pack template, list
- Takes a list of values and packs it into a binary structure, returning the string containing the structure. The template is a sequence of characters that give the order and type of values, as follows:
Character Meaning aAn ASCII string, will be null padded AAn ASCII string, will be space padded bbit string, low-to-high order (like vec())Bbit string, high-to-low order csigned char value CAn unsigned char value ddouble-precision float in the native format fsingle-precision float in the native format hhexadecimal string, low nybble first Hhexadecimal string, high nybble first isigned integer value IAn unsigned integer value lsigned long value LAn unsigned long value nshort in "network" (big-endian) order Nlong in "network" (big-endian) order ppointer to a string Ppointer to a structure (fixed-length string) ssigned short value SAn unsigned short value vshort in "VAX" (little-endian) order Vlong in "VAX" (little-endian) order uuuencoded string wBER compressed integer xnull byte XBack up a byte @Null-fill to absolute position Each character may optionally be followed by a number that gives a repeat count. Together the character and the repeat count make a field specifier. Field specifiers may be separated by whitespace, which will be ignored. With all types except
aandA, thepackfunction will gobble up that many values from the list. Saying*for the repeat count means to use however many items are left. TheaandAtypes gobble just one value, but pack it as a string of length count, padding with nulls or spaces as necessary. (When unpacking,Astrips trailing spaces and nulls, butadoes not.) Real numbers (floats and doubles) are in the native machine format only; due to the multiplicity of floating formats around, and the lack of a standard network representation, no facility for interchange has been made.The same template may generally also be used in the
unpackfunction. If you want to join variable length fields with a delimiter, use thejoinfunction.