struct.Struct

class struct.Struct(format)

Return a new Struct object which writes and reads binary data according to the format string format. Creating a Struct object once and calling its methods is more efficient than calling the struct functions with the same format since the format string only needs to be compiled once.

Compiled Struct objects support the following methods and attributes:

pack(v1, v2, ...)

Identical to the pack() function, using the compiled format. (len(result) will equal size.)

pack_into(buffer, offset, v1, v2, ...)

Identical to the pack_into() function, using the compiled format.

unpack(buffer)

Identical to the unpack() function, using the compiled format. The buffer’s size in bytes must equal size.

unpack_from(buffer, offset=0)

Identical to the unpack_from() function, using the compiled format. The buffer’s size in bytes, minus offset, must be at least size.

iter_unpack(buffer)

Identical to the iter_unpack() function, using the compiled format. The buffer’s size in bytes must be a multiple of size.

New in version 3.4.

format

The format string used to construct this Struct object.

size

The calculated size of the struct (and hence of the bytes object produced by the pack() method) corresponding to format.

doc_python
2016-10-07 17:43:30
Comments
Leave a Comment

Please login to continue.