
本文共 4089 字,大约阅读时间需要 13 分钟。
������HTML���������������������������Python struct
���������������������������������������������������������
7.1 ���structuralize Binary Data Packing
���������������������Python������C���������������������������������������������������������������������������������������������������������������������������
���������������������������������C���������������������������������Python���������������������������Notice: ������������������������������������������������������������C������������������������������������������������������������������������������������������������������������������C��������������������������������������������������������������������������������������������������������������������������������������������������������������������� native ���������������������������������������������������������������������������������������������������
Functionalities and Exceptions
������������������������������������������
struct.error
: ���������������������������������struct.pack(fmt, v1, v2, ���)
: ���������������������fmt
���������������v1, v2, ���
������������������������������������������������������������������������������struct.pack_into(fmt, buffer, offset, v1, v2, ���)
: ���������������������fmt
������������������������������������������������������������������offset
���������������������������struct.unpack(fmt, buffer)
: ���������������������fmt
������������������������
Format String
���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
Byte Order, Size, and Alignment
������������������C������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
<
/>
������������������������������������������������������������������������=
������������������������������������������������������������������������
������������������������������������������������������
- Intel x86 ��� AMD64���x86-64���������������������������
- PowerPC G5 ������������������������
- ARM ��� Intel Itanium ������������������������������
������������������C������������ sizeof
������������������������������������������������������ @
��� =
������������@
���������������������������=
���������������������������
������������������������������������������������������������������������ short
������������������������ <
, >
, =
��� !
������������������������������
Important Notes:
{0}
������������������������������Format Specification Characters
���������������������������
s
���S
���������.NET
���������������������������������Python������i
,I
,u
,Q
,q
: ���������������������f
,d
,e
,E
: ��������������������� IEEE 754 ������������������
Examples
������������������������������
���������������������������������������>>> import struct as st>>> st.pack('hhl', 1, 2, 3) # ������ bytes ������ b'\x0100\x02\x00\x03\x00\x00\x00'>>> ���������������������st.calcsize('hhl') ������ 8������������������>>> st.unpack('hhl', b'\x00\x01\x00\x02\x00\x00\x00\x03') ������ (256, 512, 50331648)
Struct Class
��������������������������������� Struct
������������������������ Struct
��������������������������������������������������������������������������������������������� struct.pack
������������
������������
pack
: ���struct.pack
���������pack_into
: ���struct.pack_into
���������unpack
: ���struct.unpack
���������unpack_from
: ���struct.unpack_from
���������iter_unpack
: ���struct.iter_unpack
���������calcsize
: ���������������������������������
Notes
struct
���������������array
���������������������������xzdrlib
��������������� XDR ���������������������������������
������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
