Generic Primitive Examples¶
[1]:
from byteclasses.print import byteclass_info, byteclass_inspect
from byteclasses.types.primitives.generics import Bit, Byte, DWord, QWord, Word
[2]:
generic_types = [Byte, Word, DWord, QWord]
for i, generic_type in enumerate(generic_types):
var = generic_type(b"\xFF" * 2**i)
byteclass_info(var)
byteclass_inspect(var)
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ Byte │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ Byte -> _Primitive -> object │ │ len() │ 1 │ │ str() │ b'\xff' │ │ repr() │ Byte(data=b'\xff', byte_order=b'@') │ │ .data │ b'\xff' │ │ .value │ b'\xff' │ └──────────────────────────┴─────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |ff │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━━━┩ │ b'\xff' │ └─────────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ Word │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ Word -> _Primitive -> object │ │ len() │ 2 │ │ str() │ b'\xff\xff' │ │ repr() │ Word(data=b'\xff\xff', byte_order=b'@') │ │ .data │ b'\xff\xff' │ │ .value │ b'\xff\xff' │ └──────────────────────────┴─────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |ff ff │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━━━━━━━┩ │ b'\xff\xff' │ └─────────────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ DWord │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ DWord -> _Primitive -> object │ │ len() │ 4 │ │ str() │ b'\xff\xff\xff\xff' │ │ repr() │ DWord(data=b'\xff\xff\xff\xff', byte_order=b'@') │ │ .data │ b'\xff\xff\xff\xff' │ │ .value │ b'\xff\xff\xff\xff' │ └──────────────────────────┴──────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |ff ff ff ff │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━━━━━━━━━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━┩ │ b'\xff\xff\xff\xff' │ └─────────────────────┘
Byteclass Info ┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Property ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ type() │ QWord │ │ is_byteclass() │ True │ │ is_collection_instance() │ False │ │ is_primitive_instance() │ True │ │ mro │ QWord -> _Primitive -> object │ │ len() │ 8 │ │ str() │ b'\xff\xff\xff\xff\xff\xff\xff\xff' │ │ repr() │ QWord(data=b'\xff\xff\xff\xff\xff\xff\xff\xff', byte_order=b'@') │ │ .data │ b'\xff\xff\xff\xff\xff\xff\xff\xff' │ │ .value │ b'\xff\xff\xff\xff\xff\xff\xff\xff' │ └──────────────────────────┴──────────────────────────────────────────────────────────────────┘
╭────────────────── Byteclass Inspect ───────────────────╮ │ 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f │ │ ---------------------------------------------------- │ │ 0x0 |ff ff ff ff ff ff ff ff │ ╰────────────────────────────────────────────────────────╯
Legend ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ b'\xff\xff\xff\xff\xff\xff\xff\xff' │ └─────────────────────────────────────┘
[3]:
bit = Bit(True) # Bit is a convenience class and is not considered a byteclass
[4]:
try:
byteclass_info(bit)
except TypeError as err:
print(err)
Object is not a byteclass instance.
[5]:
try:
byteclass_inspect(bit)
except TypeError as err:
print(err)
Object is not a byteclass instance.
[6]:
print(bit)
print(bit.value)
# Bit has no data attribute
Bit.TRUE
1