module Pack

Defined in:

lib/unpack.cr

Macro Summary

Macro Detail

macro unpack(bytes, fmt) #

Unpacks a buffer of bytes according to the given format string fmt. Returns a Tuple of unpacked values, without flattening commands that contain repeat counts or globs.

bytes must be a Bytes. fmt must be a string literal or string constant representing a valid sequence of unpacking commands.

Pack.unpack(Bytes[0x01, 0xE8, 0x03, 0x05, 0xF5, 0xE1, 0x00], "csl>") # => {1_i8, 1000_i16, 100000000}
Pack.unpack("abcd\x00ef\x00".to_slice, "CCZ*a*")                     # => {StaticArray[97_u8, 98_u8], Bytes[99, 100], Bytes[101, 102, 0]}