hbutils.binary.base

CIOType

class hbutils.binary.base.CIOType[source]
Overview:

Basic IO type. Used as base class of all the IO types.

read(file: BinaryIO)[source]

Read from binary IO object.

Parameters:

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

Returns:

Reading result.

Warning

Need to be implemented.

write(file: BinaryIO, val)[source]

Write object to binary IO object.

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

  • val – Object to write.

Warning

Need to be implemented.

CFixedType

class hbutils.binary.base.CFixedType(size: int)[source]
Overview:

Type with fixed size (such as int, uint and float).

__init__(size: int)[source]

Constructor of CFixedType.

Parameters:

size – Size of the type.

read(file: BinaryIO)[source]

Read from binary IO object.

Parameters:

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

Returns:

Reading result.

Warning

Need to be implemented.

property size

Size of the given type.

write(file: BinaryIO, val)[source]

Write object to binary IO object.

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

  • val – Object to write.

Warning

Need to be implemented.

CRangedIntType

class hbutils.binary.base.CRangedIntType(size: int, minimum: int, maximum: int)[source]
Overview:

Type with fixed size and range (such as int and uint).

__init__(size: int, minimum: int, maximum: int)[source]

Constructor of CRangedIntType.

Parameters:
  • size – Size of the type.

  • minimum – Min value of the type.

  • maximum – Max value of the type.

property maximum

Max value of the type.

property minimum

Min value of the type.

read(file: BinaryIO)[source]

Read from binary IO object.

Parameters:

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

Returns:

Reading result.

Warning

Need to be implemented.

property size

Size of the given type.

write(file: BinaryIO, val)[source]

Write object to binary IO object.

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

  • val – Object to write.

Warning

Need to be implemented.

CMarkedType

class hbutils.binary.base.CMarkedType(mark: str, size: int)[source]
Overview:

Type with struct mark, which can be directly read by struct module.

__init__(mark: str, size: int)[source]

Constructor of CMarkedType.

Parameters:
  • mark – Mark of the type.

  • size – Size of the type.

property mark

Mark of the type, will be used to read from binary data with struct module.

read(file: BinaryIO)[source]

Read from binary with struct module.

Parameters:

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

Returns:

Result value.

property size

Size of the given type.

write(file: BinaryIO, val)[source]

Write value to binary IO with struct module.

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

  • val – Writing value.