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 equalsize
.)
-
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 equalsize
.
-
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 leastsize
.
-
iter_unpack(buffer)
-
Identical to the
iter_unpack()
function, using the compiled format. The buffer’s size in bytes must be a multiple ofsize
.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 toformat
.
Please login to continue.