pack
Builtin index · Collections & strings
result = pack(values, spec, [endian="little"])
Input: values, spec, endian · Output: result
What it is
values is a vector of numbers; spec is a comma- or space-separated field list of u8 i8 u16 i16 u32 i32 u64 i64 f32 f64 (a count prefix repeats a field: "4u8").
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = pack(values, spec, [endian="little"]) | values vector or numbervalues is a vector of numbers.spec —spec is a comma- or space-separated field list of u8 i8 u16 i16 u32 i32 u64 i64 f32 f64 (a count prefix repeats a field: "4u8").endian optional (default "little")endian="big" (or "network") gives the wire order. | endian="big" —or "network" | Returns a byte buffer, a Vec of integers in 0..=255. endian="big" (or "network") gives the wire order; the default is little-endian. The number of values must equal the number of fields, and a value that does not fit its field is an error rather than being truncated. pack([1, -2, 300], "i16,i16,i16") is [1, 0, 254, 255, 44, 1]. |
Examples
No documentation example calls this form yet. The Collections & strings chapter is where one belongs.