Edge Python
Esc

Go to

Commands

Sign In

Sign in to publish packages and pin them by sha256.


By continuing, you accept our Terms and Conditions.

@
Palette

struct

0.1.0

Pack and unpack binary data in Python's formats.

@dylan·0 downloads·61.7 KB·needs edge 0.7.3·Repository
edge add struct && edge lock
bash

sha256-a9df20e63bf8ed4920a326dacd5bfa3ddf10a5948cb733a8d0377d3947bf12b7

Docs

struct

struct works like Python’s. pack turns values into bytes by a format, unpack turns them back into a tuple, and calcsize says how many bytes a format takes.

b'\x01\x00\xfe\xff\xff\xff\x00\x00\x00?'
(1, -2, 0.5)
10
Output

A format starts with its byte order. < and > pick little and big endian with standard sizes, and a format with no prefix lays its items out the way C does, each aligned to its size.

b'\x01\x02' b'\x02\x01'
8 5
Output

s is a run of bytes padded or cut to its count, c one byte and ? a bool. A Struct keeps a format, unpack_from reads at an offset and iter_unpack walks a buffer of records.

7 (b'py\x00\x00', 8, False)
b'edge' 7 True
b'py\x00\x00' 8 False
Output

A value out of range or of the wrong kind raises struct.error, which is ValueError here, and a float too large for its code raises OverflowError. pack_into is not supported, since there is no writable buffer to pack into.

out of range: 'B' format requires 0 <= number <= 255
too large: float too large to pack with e format
Output

Versions

VersionPublishedSize
0.1.0currentSeptember 28, 202661.7 KB