pack: Pack raw vectors

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

Combine values into a raw vector according to the values in template.

Usage

1
  pack(template, ...)

Arguments

template

A string, see 'Details'

...

Values/objects to be packed into a raw vector

Details

Currently supported template values are:
'a' - A null padded string
'A' - A space padded string
'b' - An ascending bit order binary vector, (must be a multiple of 8 long)
'B' - An descending bit order binary vector, (must be a multiple of 8 long)
'C' - An unsigned char (8-bit byte/octet) value
'v' - An unsigned short (16-bit) in "VAX" (little-endian) order
'V' - An unsigned long (32-bit) in "VAX" (little-endian) order
'x' - A null byte

Both 'a' and 'A' may be followed by a repeat value. A repeat value of '*' will cause the remainder of the bytes in values to be placed in the last element.

'/' allows packing and unpacking of a sequence of values where the packed structure contains a packed item count followed by the packed items themselves.

If template requires more arguments to pack than actually given, pack pads with null bytes. If template requires fewer arguments to pack than actually given, extra arguments are ignored.

Value

A raw vector following the elements in template.

Author(s)

Josh Ulrich

References

http://perldoc.perl.org/functions/pack.html

See Also

unpack

Examples

1
2
3
  (x <- pack('A4 C v A8 V', 'pack', 2, 8, 'sequence', 68098))
  (u1 <- unpack('A4 C H*', x))
  (u2 <- unpack('v/A V', u1[[3]]))

joshuaulrich/pack documentation built on May 19, 2019, 8:55 p.m.