The package registry is still being built. The docs are live, everything else is a preview.

Edge Python

Sign In

Sign in to publish packages and pin them by sha256.


By continuing, you accept our Terms and Conditions.

@
Palette

struct (js, cli)

struct packs primitive values into bytes and back. Declare it with edge add struct and import it by bare name. To pin a different version, point the edge.json entry at another URL, see Modules.

Functions are pack(fmt, *values), unpack(fmt, data), and calcsize(fmt). Codes are x b B ? h H i I q Q f d with repeat counts, and byte-order prefixes are < (the default), =, >, !. There is no native-alignment mode. unpack returns a list. A packed buffer crosses the host boundary once, which makes it the fast lane for bulk numeric data. Out-of-range integers raise ValueError, non-integer values for integer codes raise TypeError, and f / d accept integers. Not implemented: s / p strings, e half floats, n / N, and pack_into / unpack_from / iter_unpack.

cmd + enter
[92.5, -115.25, 0.75]
4
Output

The byte-order prefix picks the layout:

cmd + enter
b'\x02\x01'
b'\x01\x02'
[70000]
Output

A value that does not fit its code raises ValueError:

cmd + enter
out of range: argument out of range for 'B'
Output