Signed field


In [1]:
from konfoo import Index, Byteorder, Signed, Signed8, Signed16, Signed24, Signed32, Signed64

Item

Item type of the field class.


In [2]:
Signed.item_type


Out[2]:
ItemClass.Signed = 44

Checks if the field class is a bit field.


In [3]:
Signed.is_bit()


Out[3]:
False

Checks if the field class is a boolean field.


In [4]:
Signed.is_bool()


Out[4]:
False

Checks if the field class is a decimal number field.


In [5]:
Signed.is_decimal()


Out[5]:
True

Checks if the field class is a floating point number field.


In [6]:
Signed.is_float()


Out[6]:
False

Checks if the field class is a pointer field.


In [7]:
Signed.is_pointer()


Out[7]:
False

Checks if the field class is a stream field.


In [8]:
Signed.is_stream()


Out[8]:
False

Checks if the field class is a string field.


In [9]:
Signed.is_string()


Out[9]:
False

Field


In [10]:
signed = Signed(bit_size=32, align_to=None, byte_order='auto')

In [11]:
signed = Signed(32)

Field view


In [12]:
signed


Out[12]:
Signed(index=Index(byte=0, bit=0, address=0, base_address=0, update=False), alignment=Alignment(byte_size=4, bit_offset=0), bit_size=32, value=0)

In [13]:
str(signed)


Out[13]:
'Signed32(Index(byte=0, bit=0, address=0, base_address=0, update=False), Alignment(byte_size=4, bit_offset=0), 32, 0)'

In [14]:
repr(signed)


Out[14]:
'Signed(index=Index(byte=0, bit=0, address=0, base_address=0, update=False), alignment=Alignment(byte_size=4, bit_offset=0), bit_size=32, value=0)'

Field name


In [15]:
signed.name


Out[15]:
'Signed32'

Field index


In [16]:
signed.index


Out[16]:
Index(byte=0, bit=0, address=0, base_address=0, update=False)

Byte index of the field within the byte stream.


In [17]:
signed.index.byte


Out[17]:
0

Bit offset relative to the byte index of the field within the byte stream.


In [18]:
signed.index.bit


Out[18]:
0

Absolute address of the field within the data source.


In [19]:
signed.index.address


Out[19]:
0

Base address of the byte stream within the data source.


In [20]:
signed.index.base_address


Out[20]:
0

Indexes the field and returns the index after the field.


In [21]:
signed.index_field(index=Index())


Out[21]:
Index(byte=4, bit=0, address=4, base_address=0, update=False)

Field alignment


In [22]:
signed.alignment


Out[22]:
Alignment(byte_size=4, bit_offset=0)

Byte size of the field group which the field is aligned to.


In [23]:
signed.alignment.byte_size


Out[23]:
4

Bit offset of the field within its aligned field group.


In [24]:
signed.alignment.bit_offset


Out[24]:
0

Field size


In [25]:
signed.bit_size


Out[25]:
32

Field byte order


In [26]:
signed.byte_order


Out[26]:
Byteorder.auto = 'auto'

In [27]:
signed.byte_order.value


Out[27]:
'auto'

In [28]:
signed.byte_order.name


Out[28]:
'auto'

In [29]:
signed.byte_order = 'auto'

In [30]:
signed.byte_order = Byteorder.auto

Field value

Checks if the decimal field is signed or unsigned.


In [31]:
signed.signed


Out[31]:
True

Maximal decimal field value.


In [32]:
signed.max()


Out[32]:
2147483647

Minimal decimal field value.


In [33]:
signed.min()


Out[33]:
-2147483648

Returns the decimal field value as an integer number.


In [34]:
signed.value


Out[34]:
0

Returns the decimal field value aligned to its field group as a number of bytes.


In [35]:
bytes(signed)


Out[35]:
b'\x00\x00\x00\x00'

In [36]:
bytes(signed).hex()


Out[36]:
'00000000'

Returns the decimal field value as an integer number.


In [37]:
int(signed)


Out[37]:
0

Returns the decimal field value as an floating point number.


In [38]:
float(signed)


Out[38]:
0.0

Returns the decimal field value as a lowercase hexadecimal string prefixed with 0x.


In [39]:
hex(signed)


Out[39]:
'0x0'

Returns the decimal field value as a binary string prefixed with 0b.


In [40]:
bin(signed)


Out[40]:
'0b0'

Returns the decimal field value as an octal string prefixed with 0o.


In [41]:
oct(signed)


Out[41]:
'0o0'

Returns the decimal field value as a boolean value.


In [42]:
bool(signed)


Out[42]:
False

Returns the decimal field value as a signed integer number.


In [43]:
signed.as_signed()


Out[43]:
0

Returns the decimal field value as an unsigned integer number.


In [44]:
signed.as_unsigned()


Out[44]:
0

Field metadata

Returns the meatadata of the field as an ordered dictionary.


In [45]:
signed.describe()


Out[45]:
OrderedDict([('address', 0),
             ('alignment', [4, 0]),
             ('class', 'Signed32'),
             ('index', [0, 0]),
             ('max', 2147483647),
             ('min', -2147483648),
             ('name', 'Signed32'),
             ('order', 'auto'),
             ('signed', True),
             ('size', 32),
             ('type', 'Field'),
             ('value', 0)])

Deserialize


In [46]:
signed.deserialize(bytes.fromhex('00010000'), byte_order='little')


Out[46]:
Index(byte=4, bit=0, address=4, base_address=0, update=False)

In [47]:
signed.value


Out[47]:
256

In [48]:
bytes(signed)


Out[48]:
b'\x00\x01\x00\x00'

In [49]:
bytes(signed).hex()


Out[49]:
'00010000'

In [50]:
int(signed)


Out[50]:
256

In [51]:
float(signed)


Out[51]:
256.0

In [52]:
hex(signed)


Out[52]:
'0x100'

In [53]:
bin(signed)


Out[53]:
'0b100000000'

In [54]:
oct(signed)


Out[54]:
'0o400'

In [55]:
bool(signed)


Out[55]:
True

Serialize


In [56]:
buffer = bytearray()

In [57]:
signed.value = 256

In [58]:
signed.value = 256.0

In [59]:
signed.value = 0x100

In [60]:
signed.value = 0b100000000

In [61]:
signed.value = 0o400

In [62]:
signed.value = False

In [63]:
signed.value = 256

In [64]:
signed.serialize(buffer, byte_order='little')


Out[64]:
Index(byte=4, bit=0, address=4, base_address=0, update=False)

In [65]:
buffer.hex()


Out[65]:
'00010000'

In [66]:
bytes(signed).hex()


Out[66]:
'00010000'

In [ ]: