Primitive types¶
Primitive types include byte-aligned types like integer numbers, floating point numbers and bit-aligned types like flags, bitfields and also flags.
ByteType¶
ByteType is an abstract super class which can be used to create byte types.
digraph inheritance0a5fe52165 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "oser.core.ArithmeticEmulationMixin" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled"]; "oser.core.ByteType" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="A ``ByteType`` is an abstract class for byte types."]; "oser.core.FuzzingTypeMixin" -> "oser.core.ByteType" [arrowsize=0.5,style="setlinewidth(0.5)"]; "oser.core.ArithmeticEmulationMixin" -> "oser.core.ByteType" [arrowsize=0.5,style="setlinewidth(0.5)"]; "oser.core.OserNode" -> "oser.core.ByteType" [arrowsize=0.5,style="setlinewidth(0.5)"]; "oser.core.FuzzingTypeMixin" [URL="fuzzing.html#oser.core.FuzzingTypeMixin",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A type mixin for fuzzing tests."]; "oser.core.OserNode" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled"]; }-
class
oser.
ByteType
(value=0)¶ A
ByteType
is an abstract class for byte types.- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Naming conventions¶
A type that starts with an "S"
is signed.
A type that starts with an "U"
is unsigned.
A type that has a "L"
as second character is little endian.
A type that has a "B"
as second character is big endian.
8-Bit types¶
SLInt8¶
Signed, little endian 8-Bit integer.
-
class
oser.
SLInt8
(value=0)¶ Signed, little endian 8-Bit integer.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import SLInt8
>>> from oser import to_hex
>>> instance = SLInt8(-10)
>>>
>>> print(instance)
-10 (SLInt8)
>>> print(instance.introspect())
0 \xf6 -10 (SLInt8)
>>> binary = instance.encode()
>>> print(to_hex(binary))
0
\xF6
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
1
>>> print(instance)
-10 (SLInt8)
SBInt8¶
Signed, big endian 8-Bit integer.
-
class
oser.
SBInt8
(value=0)¶ Signed, big endian 8-Bit integer.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import SBInt8
>>> from oser import to_hex
>>> instance = SBInt8(-10)
>>> print(instance)
-10 (SBInt8)
>>> print(instance.introspect())
0 \xf6 -10 (SBInt8)
>>> binary = instance.encode()
>>> print(to_hex(binary))
0
\xF6
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
1
>>> print(instance)
-10 (SBInt8)
ULInt8¶
Unsigned, little endian 8-Bit integer.
-
class
oser.
ULInt8
(value=0)¶ Unsigned, little endian 8-Bit integer.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import ULInt8
>>> from oser import to_hex
>>> instance = ULInt8(10)
>>> print(instance)
10 (ULInt8)
>>> print(instance.introspect())
0 \x0a 10 (ULInt8)
>>> binary = instance.encode()
>>> print(to_hex(binary))
0
\x0A
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
1
>>> print(instance)
10 (ULInt8)
UBInt8¶
Unsigned, big endian 8-Bit integer.
-
class
oser.
UBInt8
(value=0)¶ Unsigned, big endian 8-Bit integer.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import UBInt8
>>> from oser import to_hex
>>> instance = UBInt8(10)
>>>
>>> print(instance)
10 (UBInt8)
>>> print(instance.introspect())
0 \x0a 10 (UBInt8)
>>> binary = instance.encode()
>>> print(to_hex(binary))
0
\x0A
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
1
>>> print(instance)
10 (UBInt8)
Padding¶
Unsigned 8-Bit integer as a fixed pattern. The pattern to use as a placeholder can be set.
If strict is used the input data is checked while encoding to match the pattern. If input data and pattern do not match a ValueError is raised and decoding is stopped immediately.
-
class
oser.
Padding
(value=b'\x00', strict=False)¶ Unsigned 8-Bit integer to fill data with a pattern.
- Parameters
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import Padding
>>> from oser import to_hex
>>> instance = Padding(value="\x00", strict=True)
>>> print(instance)
\x00 (Padding)
>>> print(instance.introspect())
0 \x00 \x00 (Padding)
>>> binary = instance.encode()
>>> print(to_hex(binary))
0
\x00
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
1
>>> print(instance)
\x00 (Padding)
>>> instance.decode("\xff")
oser.DecodeException: Data could not be decoded!
Parsing object is:
0 \xff \xff (Padding)
^^^^ value not allowed: expected \x00 but found \xff
16-Bit types¶
SLInt16¶
Signed, little endian 16-Bit integer.
-
class
oser.
SLInt16
(value=0)¶ Signed, little endian 16-Bit integer.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import SLInt16
>>> from oser import to_hex
>>> instance = SLInt16(-1000)
>>> print(instance)
-1000 (SLInt16)
>>> print(instance.introspect())
0 \x18 -1000 (SLInt16)
1 \xfc
>>> binary = instance.encode()
>>> print(to_hex(binary))
0| 1
\x18\xFC
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
2
>>> print(instance)
-1000 (SLInt16)
SBInt16¶
Signed, bit endian 16-Bit integer.
-
class
oser.
SBInt16
(value=0)¶ Signed, bit endian 16-Bit integer.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import SBInt16
>>> from oser import to_hex
>>> instance = SBInt16(-1000)
>>> print(instance)
-1000 (SBInt16)
>>> print(instance.introspect())
0 \xfc -1000 (SBInt16)
1 \x18
>>> binary = instance.encode()
>>> print(to_hex(binary))
0| 1
\xFC\x18
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
2
>>> print(instance)
-1000 (SBInt16)
ULInt16¶
Unsigned, little endian 16-Bit integer.
-
class
oser.
ULInt16
(value=0)¶ Unsigned, little endian 16-Bit integer.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import ULInt16
>>> from oser import to_hex
>>> instance = ULInt16(1000)
>>> print(instance)
1000 (ULInt16)
>>> print(instance.introspect())
0 \xe8 1000 (ULInt16)
1 \x03
>>> binary = instance.encode()
>>> print(to_hex(binary))
0| 1
\xE8\x03
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
2
>>> print(instance)
1000 (ULInt16)
UBInt16¶
Unsigned, big endian 16-Bit integer.
-
class
oser.
UBInt16
(value=0)¶ Unsigned, big endian 16-Bit integer.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import UBInt16
>>> from oser import to_hex
>>> instance = UBInt16(1000)
>>> print(instance)
1000 (UBInt16)
>>> print(instance.introspect())
0 \x03 1000 (UBInt16)
1 \xe8
>>> binary = instance.encode()
>>> print(to_hex(binary))
0| 1
\x03\xE8
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
2
>>> print(instance)
1000 (UBInt16)
32-Bit types¶
SLInt32¶
Signed, little endian 32-Bit integer.
-
class
oser.
SLInt32
(value=0)¶ Signed, little endian 32-Bit integer.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import SLInt32
>>> from oser import to_hex
>>> instance = SLInt32(-70000)
>>> print(instance)
-70000 (SLInt32)
>>> print(instance.introspect())
0 \x90 -70000 (SLInt32)
1 \xee
2 \xfe
3 \xff
>>> binary = instance.encode()
>>> print(to_hex(binary))
0| 1| 2| 3
\x90\xEE\xFE\xFF
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
4
>>> print(instance)
-70000 (SLInt32)
SBInt32¶
Signed, big endian 32-Bit integer.
-
class
oser.
SBInt32
(value=0)¶ Signed, big endian 32-Bit integer.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import SBInt32
>>> from oser import to_hex
>>> instance = SBInt32(-70000)
>>> print(instance)
-70000 (SBInt32)
>>> print(instance.introspect())
0 \xff -70000 (SBInt32)
1 \xfe
2 \xee
3 \x90
>>> binary = instance.encode()
>>> print(to_hex(binary))
0| 1| 2| 3
\xFF\xFE\xEE\x90
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
4
>>> print(instance)
-70000 (SBInt32)
ULInt32¶
Unsigned, little endian 32-Bit integer.
-
class
oser.
ULInt32
(value=0)¶ Unsigned, little endian 32-Bit integer.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import ULInt32
>>> from oser import to_hex
>>> instance = ULInt32(70000)
>>> print(instance)
70000 (ULInt32)
>>> print(instance.introspect())
0 \x70 70000 (ULInt32)
1 \x11
2 \x01
3 \x00
>>> binary = instance.encode()
>>> print(to_hex(binary))
0| 1| 2| 3
\x70\x11\x01\x00
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
4
>>> print(instance)
70000 (ULInt32)
UBInt32¶
Unsigned, big endian 32-Bit integer.
-
class
oser.
UBInt32
(value=0)¶ Unsigned, big endian 32-Bit integer.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import UBInt32
>>> from oser import to_hex
>>> instance = UBInt32(70000)
>>> print(instance)
70000 (UBInt32)
>>> print(instance.introspect())
0 \x00 70000 (UBInt32)
1 \x01
2 \x11
3 \x70
>>> binary = instance.encode()
>>> print(to_hex(binary))
0| 1| 2| 3
\x00\x01\x11\x70
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
4
>>> print(instance)
70000 (UBInt32)
64-Bit types¶
SLInt64¶
Signed, little endian 64-Bit integer.
-
class
oser.
SLInt64
(value=0)¶ Signed, little endian 64-Bit integer.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import SLInt64
>>> from oser import to_hex
>>> instance = SLInt64(-7000000)
>>> print(instance)
-7000000 (SLInt64)
>>> print(instance.introspect())
0 \x40 -7000000 (SLInt64)
1 \x30
2 \x95
3 \xff
4 \xff
5 \xff
6 \xff
7 \xff
>>> binary = instance.encode()
>>> print(to_hex(binary))
0| 1| 2| 3| 4| 5| 6| 7
\x40\x30\x95\xFF\xFF\xFF\xFF\xFF
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
8
>>> print(instance)
-7000000 (SLInt64)
SBInt64¶
Signed, big endian 64-Bit integer.
-
class
oser.
SBInt64
(value=0)¶ Signed, big endian 64-Bit integer.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import SBInt64
>>> from oser import to_hex
>>> instance = SBInt64(-7000000)
>>> print(instance)
-7000000 (SBInt64)
>>> print(instance.introspect())
0 \xff -7000000 (SBInt64)
1 \xff
2 \xff
3 \xff
4 \xff
5 \x95
6 \x30
7 \x40
>>> binary = instance.encode()
>>> print(to_hex(binary))
0| 1| 2| 3| 4| 5| 6| 7
\xFF\xFF\xFF\xFF\xFF\x95\x30\x40
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
8
>>> print(instance)
-7000000 (SBInt64)
ULInt64¶
Unsigned, little endian 64-Bit integer.
-
class
oser.
ULInt64
(value=0)¶ Unsigned, little endian 64-Bit integer.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import ULInt64
>>> from oser import to_hex
>>> instance = ULInt64(7000000)
>>> print(instance)
7000000 (ULInt64)
>>> print(instance.introspect())
0 \xc0 7000000 (ULInt64)
1 \xcf
2 \x6a
3 \x00
4 \x00
5 \x00
6 \x00
7 \x00
>>> binary = instance.encode()
>>> print(to_hex(binary))
0| 1| 2| 3| 4| 5| 6| 7
\xC0\xCF\x6A\x00\x00\x00\x00\x00
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
8
>>> print(instance)
7000000 (ULInt64)
UBInt64¶
Unsigned, big endian 64-Bit integer.
-
class
oser.
UBInt64
(value=0)¶ Unsigned, big endian 64-Bit integer.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import UBInt64
>>> from oser import to_hex
>>> instance = UBInt64(7000000)
>>> print(instance)
7000000 (UBInt64)
>>> print(instance.introspect())
0 \x00 7000000 (UBInt64)
1 \x00
2 \x00
3 \x00
4 \x00
5 \x6a
6 \xcf
7 \xc0
>>> binary = instance.encode()
>>> print(to_hex(binary))
0| 1| 2| 3| 4| 5| 6| 7
\x00\x00\x00\x00\x00\x6A\xCF\xC0
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
8
>>> print(instance)
7000000 (UBInt64)
Variable length integers¶
Variable length integers transport 7
bits of information per transferred byte.
The msb of the transferred bytes indicate the last byte of a variable length integer.
All msbs are set except the last one.
Signed values are first converted into an unsigned representation using the zigzag-encoding. This way only one additional bit must be used for the sign.
Zigzag-encoding is done by multiplying a number by 2
. If the number is negative
it is xor’ed by -1
(all bits set) so that all leading sign bits are inverted.
Negative numbers become odd. Positive numbers become even.
original value |
zigzag-encoded value |
---|---|
0 |
0 |
-1 |
1 |
1 |
2 |
-2 |
3 |
2 |
4 |
-3 |
5 |
3 |
6 |
… |
… |
Zigzag-decoding is done by dividing the encoded number by 2
.
If the number was odd it is xor’ed by -1
(all bits set) to convert it back into the normal representation.
UBVarInt¶
Unsigned, big endian variable length integer.
-
class
oser.
UBVarInt
(value=0)¶ Unsigned, big endian variable length integer.
- Parameters
value=0 (int) – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import UBVarInt
>>> from oser import to_hex
>>> instance = UBVarInt(1)
>>> print(instance)
1 (UBVarInt)
>>> print(instance.introspect())
0 \x01 1 (UBVarInt)
>>> binary = instance.encode()
>>> print(to_hex(binary))
0
\x01
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
1
>>> print(instance)
1 (UBVarInt)
>>> instance.set(150)
>>> print(instance.introspect())
0 \x81 150 (UBVarInt)
1 \x16
>>> instance.set(15000000000)
>>> print(instance.introspect())
0 \x80 15000000000 (UBVarInt)
1 \xb7
2 \xf0
3 \xc7
4 \xac
5 \x00
ULVarInt¶
Unsigned, little endian variable length integer.
-
class
oser.
ULVarInt
(value=0)¶ Unsigned, little endian variable length integer.
- Parameters
value=0 (int) – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import ULVarInt
>>> from oser import to_hex
>>> instance = ULVarInt(1)
>>> print(instance)
1 (ULVarInt)
>>> print(instance.introspect())
0 \x01 1 (ULVarInt)
>>> binary = instance.encode()
>>> print(to_hex(binary))
0
\x01
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
1
>>> print(instance)
1 (ULVarInt)
>>> instance.set(150)
>>> print(instance.introspect())
0 \x96 150 (ULVarInt)
1 \x01
>>> instance.set(15000000000)
>>> print(instance.introspect())
0 \x80 15000000000 (ULVarInt)
1 \xac
2 \xc7
3 \xf0
4 \xb7
5 \x00
SBVarInt¶
Signed, big endian variable length integer.
-
class
oser.
SBVarInt
(value=0)¶ Signed, big endian variable length integer.
- Parameters
value=0 (int) – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import SBVarInt
>>> from oser import to_hex
>>> instance = SBVarInt(-1)
>>> print(instance)
-1 (SBVarInt)
>>> print(instance.introspect())
0 \x01 -1 (SBVarInt)
>>> binary = instance.encode()
>>> print(to_hex(binary))
0
\x01
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
1
>>> print(instance)
-1 (SBVarInt)
>>> instance.set(150)
>>> print(instance.introspect())
0 \x82 150 (SBVarInt)
1 \x2c
>>> instance.set(-150)
>>> print(instance.introspect())
0 \x82 -150 (SBVarInt)
1 \x2b
>>> instance.set(15000000000)
>>> print(instance.introspect())
0 \x80 15000000000 (SBVarInt)
1 \xef
2 \xe1
3 \x8e
4 \xd8
5 \x00
>>> instance.set(-15000000000)
>>> print(instance.introspect())
0 \x80 -15000000000 (SBVarInt)
1 \xef
2 \xe1
3 \x8e
4 \xd7
5 \x7f
SLVarInt¶
Signed, little endian variable length integer.
-
class
oser.
SLVarInt
(value=0)¶ Signed, little endian variable length integer.
- Parameters
value=0 (int) – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import SLVarInt
>>> from oser import to_hex
>>> instance = SLVarInt(-1)
>>> print(instance)
-1 (SLVarInt)
>>> print(instance.introspect())
0 \x01 -1 (SLVarInt)
>>> binary = instance.encode()
>>> print(to_hex(binary))
0
\x01
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
1
>>> print(instance)
-1 (SLVarInt)
>>> instance.set(150)
>>> print(instance.introspect())
0 \xac 150 (SLVarInt)
1 \x02
>>> instance.set(-150)
>>> print(instance.introspect())
0 \xab -150 (SLVarInt)
1 \x02
>>> instance.set(15000000000)
>>> print(instance.introspect())
0 \x80 15000000000 (SLVarInt)
1 \xd8
2 \x8e
3 \xe1
4 \xef
5 \x00
>>> instance.set(-15000000000)
>>> print(instance.introspect())
0 \xff -15000000000 (SLVarInt)
1 \xd7
2 \x8e
3 \xe1
4 \xef
5 \x00
Float types¶
LFloat¶
Little endian 32-Bit float.
-
class
oser.
LFloat
(value=0)¶ Little endian 32-Bit float.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import LFloat
>>> from oser import to_hex
>>> instance = LFloat(-12345)
>>> print(instance)
-12345 (LFloat)
>>> print(instance.introspect())
0 \x00 -12345 (LFloat)
1 \xe4
2 \x40
3 \xc6
>>> binary = instance.encode()
>>> print(to_hex(binary))
0| 1| 2| 3
\x00\xE4\x40\xC6
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
4
>>> print(instance)
-12345.0 (LFloat)
BFloat¶
Big endian 32-Bit float.
-
class
oser.
BFloat
(value=0)¶ Big endian 32-Bit float.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import BFloat
>>> from oser import to_hex
>>> instance = BFloat(-12345)
>>> print(instance)
-12345 (BFloat)
>>> print(instance.introspect())
0 \xc6 -12345 (BFloat)
1 \x40
2 \xe4
3 \x00
>>> binary = instance.encode()
>>> print(to_hex(binary))
0| 1| 2| 3
\xC6\x40\xE4\x00
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
4
>>> print(instance)
-12345.0 (BFloat)
Double types¶
LDouble¶
Little endian 64-Bit float.
-
class
oser.
LDouble
(value=0)¶ Little endian 64-Bit float.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import LDouble
>>> from oser import to_hex
>>> instance = LDouble(-12345)
>>> print(instance)
-12345 (LDouble)
>>> print(instance.introspect())
0 \x00 -12345 (LDouble)
1 \x00
2 \x00
3 \x00
4 \x80
5 \x1c
6 \xc8
7 \xc0
>>> binary = instance.encode()
>>> print(to_hex(binary))
0| 1| 2| 3| 4| 5| 6| 7
\x00\x00\x00\x00\x80\x1C\xC8\xC0
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
8
>>> print(instance)
-12345.0 (LDouble)
BDouble¶
Big endian 64-Bit float.
-
class
oser.
BDouble
(value=0)¶ Big endian 64-Bit float.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import BDouble
>>> from oser import to_hex
>>> instance = BDouble(-12345)
>>> print(instance)
-12345 (BDouble)
>>> print(instance.introspect())
0 \xc0 -12345 (BDouble)
1 \xc8
2 \x1c
3 \x80
4 \x00
5 \x00
6 \x00
7 \x00
>>> binary = instance.encode()
>>> print(to_hex(binary))
0| 1| 2| 3| 4| 5| 6| 7
\xC0\xC8\x1C\x80\x00\x00\x00\x00
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
8
>>> print(instance)
-12345.0 (BDouble)
BitType¶
oser.BitType
is an abstract super class which can be used to create
bit types.
oser.BitType
should not be used alone but within a oser.BitStruct
as a member since
oser.BitType
decodes and encodes bitstrings not bytestrings.
-
class
oser.
BitType
(value=0)¶ A
BitType
is an abstract class for bit types.- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bits that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
up
()¶ Return the parent element.
Bit types¶
Flag¶
1-Bit value used as a flag in a bit context.
-
class
oser.
Flag
(value=0)¶ 1-Bit value used as a flag in a bit context.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bits that were decoded.
- Parameters
- Returns
the number of bits that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
up
()¶ Return the parent element.
Usage:
>>> from oser import Flag
>>> instance = Flag(1)
>>> print(instance)
1 (Flag)
>>> print(instance.introspect())
0.7 1 1 (Flag)
>>> bitString = instance.encode()
>>> print(bitString)
1
>>> bitsDecoded = instance.decode(bitString)
>>> print(bitsDecoded)
1
>>> print(instance)
1 (Flag)
Nibble¶
4-Bit value in a bit context.
-
class
oser.
Nibble
(value=0)¶ 4-Bit value in a bit context.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bits that were decoded.
- Parameters
- Returns
the number of bits that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
up
()¶ Return the parent element.
Usage:
>>> from oser import Nibble
>>> instance = Nibble(7)
>>> print(instance)
7 (Nibble)
>>> print(instance.introspect())
0.7 0 7 (Nibble)
0.6 1
0.5 1
0.4 1
>>> bitString = instance.encode()
>>> print(bitString)
0111
>>> bitsDecoded = instance.decode(bitString)
>>> print(bitsDecoded)
4
>>> print(instance)
7 (Nibble)
BitField¶
N-Bit value with a variable length in a bit context.
-
class
oser.
BitField
(value=0, length=1)¶ N-Bit value with a variable length in a bit context.
Initialize a
BitField
.-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bits that were decoded.
- Parameters
- Returns
the number of bits that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
up
()¶ Return the parent element.
-
Usage:
>>> from oser import BitField
>>> instance = BitField(value=0xabc, length=12)
>>> print(instance)
2748 (BitField(12))
>>> print(instance.introspect())
0.7 1 2748 (BitField(12))
0.6 0
0.5 1
0.4 0
0.3 1
0.2 0
0.1 1
0.0 1
1.7 1
1.6 1
1.5 0
1.4 0
>>> bitString = instance.encode()
>>> print(bitString)
101010111100
>>> bitsDecoded = instance.decode(bitString)
>>> print(bitsDecoded)
12
>>> print(instance)
2748 (BitField(12))
PaddingFlag¶
1-Bit padding value used as a flag in a bit context. Value is fixed and may be strict. If strict is set the input data and the value are compared with each other. If the values differe a ValueError is raised.
-
class
oser.
PaddingFlag
(value=False, strict=False)¶ PaddingFlag is a one bit padding.
- Parameters
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bits that were decoded.
- Parameters
- Returns
the number of bits that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
up
()¶ Return the parent element.
Usage:
>>> from oser import PaddingFlag
>>> instance = PaddingFlag(value=1, strict=True)
>>> print(instance)
1 (PaddingFlag)
>>> print(instance.introspect())
0.7 1 1 (PaddingFlag)
>>> bitString = instance.encode()
>>> print(bitString)
1
>>> bitsDecoded = instance.decode(bitString)
>>> print(bitsDecoded)
1
>>> print(instance)
1 (PaddingFlag)
>>> instance.decode("0")
Exception: Padding error: expected 1 got 0!
Null¶
A null object. It does not lead to any data but can be used as a placeholder or in case of an unused else branch, etc.
-
class
oser.
Null
¶ A null-object that does not contain any data.
- Parameters
value – the initial value.
-
byte_size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded (always 0).
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string. This is always an empty string.
-
get
()¶ Return the value.
- Returns
the value.
-
introspect
(stop_at=None)¶ Return the introspection representation of the object as a string.
-
root
()¶ return root element
-
set
(value)¶ Set the value. Always raises an Exception.
- Parameters
value – the new value
-
set_fuzzing_values
(values)¶ Set fuzzing values.
- Parameters
values (iterable) – the values used for fuzzing.
-
size
()¶ Return the length of the byte type in bytes.
- Returns
the length of the byte type in bytes.
- Return type
-
up
()¶ Return the parent element.
Usage:
>>> from oser import to_hex
>>> instance = Null()
>>> print(instance)
Null (Null)
>>> print(instance.introspect())
- - Null
>>> binary = instance.encode()
>>> print(to_hex(binary))
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
0
>>> print(instance)
Null (Null)
Nothing¶
An invisible object. It can be used to hide members in special conditions.
-
class
oser.
Nothing
¶ Nothing
does not appear in the encoded data and not in the string or intorspection.Args: value: the initial value.
-
decode
(data, full_data=b'', context_data=b'')¶ Decode a binary string and return the number of bytes that were decoded.
- Parameters
- Returns
the number of bytes that were decoded.
- Return type
-
encode
(full_data=b'', context_data=b'')¶ Return the encoded binary string. This is always an empty string.
-
get
()¶ Always returns
None
.- Returns
None
-
set
(value)¶ Set the value. Always raises an Exception.
- Parameters
value – the new value
-
Usage:
>>> from oser import Nothing
>>> from oser import to_hex
>>> instance = Nothing()
>>> print(instance)
>>> print(instance.introspect())
>>> binary = instance.encode()
>>> print(to_hex(binary))
>>> bytesDecoded = instance.decode(binary)
>>> print(bytesDecoded)
0
>>> print(instance)