hbutils.binary.bool

CBoolType

class hbutils.binary.bool.CBoolType(size: int)[source]
Overview:

Boolean type.

__init__(size: int)[source]

Constructor of CBoolType.

Parameters:

size – Size of boolean type.

read(file: BinaryIO) → bool[source]

Read boolean value.

Parameters:

file – Binary file, io.BytesIO is supported as well.

Returns:

Boolean value.

property size

Size of the given type.

write(file: BinaryIO, val: bool)[source]

Write boolean value to binary IO object.

Parameters:
  • file – Binary file, io.BytesIO is supported as well.

  • val – Boolean value to write.

c_bool

hbutils.binary.bool.c_bool = <hbutils.binary.bool.CBoolType object>
Overview:

Reading and writing bool value like C language.

Examples::
>>> import io
>>> from hbutils.binary import c_bool
>>> 
>>> with io.BytesIO(b'\x01\x00\x01\x00') as file:
...     print(c_bool.read(file))
...     print(c_bool.read(file))
...     print(c_bool.read(file))
...     print(c_bool.read(file))
True
False
True
False
>>> with io.BytesIO() as file:
...     c_bool.write(file, True)
...     c_bool.write(file, False)
...     c_bool.write(file, True)
...     c_bool.write(file, False)
...     print(file.getvalue())
... 
b'\x01\x00\x01\x00'