String field


In [1]:
from konfoo import Index, Byteorder, String

Item

Item type of the field class.


In [2]:
String.item_type


Out[2]:
ItemClass.String = 21

Checks if the field class is a bit field.


In [3]:
String.is_bit()


Out[3]:
False

Checks if the field class is a boolean field.


In [4]:
String.is_bool()


Out[4]:
False

Checks if the field class is a decimal number field.


In [5]:
String.is_decimal()


Out[5]:
False

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


In [6]:
String.is_float()


Out[6]:
False

Checks if the field class is a pointer field.


In [7]:
String.is_pointer()


Out[7]:
False

Checks if the field class is a stream field.


In [8]:
String.is_stream()


Out[8]:
True

Checks if the field class is a string field.


In [9]:
String.is_string()


Out[9]:
True

Field


In [10]:
string = String(size=0)

In [11]:
string = String()

Field view


In [12]:
string


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

In [13]:
str(string)


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

In [14]:
repr(string)


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

Field name


In [15]:
string.name


Out[15]:
'String'

Field index


In [16]:
string.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]:
string.index.byte


Out[17]:
0

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


In [18]:
string.index.bit


Out[18]:
0

Absolute address of the field within the data source.


In [19]:
string.index.address


Out[19]:
0

Base address of the byte stream within the data source.


In [20]:
string.index.base_address


Out[20]:
0

Indexes the field and returns the index after the field.


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


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

Field alignment


In [22]:
string.alignment


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

Byte size of the aligned field group.


In [23]:
string.alignment.byte_size


Out[23]:
0

Bit offset of field in the aligned field group.


In [24]:
string.alignment.bit_offset


Out[24]:
0

Field size


In [25]:
string.bit_size


Out[25]:
0

Field length


In [26]:
len(string)


Out[26]:
0

In [27]:
bool(string)


Out[27]:
False

Field byte order


In [28]:
string.byte_order


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

In [29]:
string.byte_order.value


Out[29]:
'auto'

In [30]:
string.byte_order.name


Out[30]:
'auto'

In [31]:
string.byte_order = 'auto'

In [32]:
string.byte_order = Byteorder.auto

Field value

Checks if the string field is zero-terminated.


In [33]:
string.is_terminated()


Out[33]:
False

Returns the string field value as an ascii encoded string.


In [34]:
string.value


Out[34]:
''

Returns the string field value as a number of bytes.


In [35]:
bytes(string)


Out[35]:
b''

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


Out[36]:
''

Returns the string field value as a lowercase hexadecimal encoded string.


In [37]:
string.hex()


Out[37]:
''

Field metadata

Returns the meatadata of the field as an ordered dictionary.


In [38]:
string.describe()


Out[38]:
OrderedDict([('address', 0),
             ('alignment', [0, 0]),
             ('class', 'String'),
             ('index', [0, 0]),
             ('name', 'String'),
             ('order', 'auto'),
             ('size', 0),
             ('type', 'Field'),
             ('value', '')])

Field Resize

Resizing the string field.


In [39]:
string.resize(6)

View of the string field.


In [40]:
string


Out[40]:
String(index=Index(byte=0, bit=0, address=0, base_address=0, update=False), alignment=Alignment(byte_size=6, bit_offset=0), bit_size=48, value='')

Index of the string field.


In [41]:
string.index


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

Name of the string field.


In [42]:
string.name


Out[42]:
'String6'

Alignment of the string field.


In [43]:
string.alignment


Out[43]:
Alignment(byte_size=6, bit_offset=0)

Bit size of the string field.


In [44]:
string.bit_size


Out[44]:
48

Byte length of the string field.


In [45]:
len(string)


Out[45]:
6

In [46]:
bool(string)


Out[46]:
True

Value of the string field


In [47]:
string.value


Out[47]:
''

In [48]:
bytes(string)


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

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


Out[49]:
'000000000000'

In [50]:
string.hex()


Out[50]:
'000000000000'

In [51]:
string.is_terminated()


Out[51]:
True

Deserialize


In [52]:
string.deserialize(b'Konfoo')


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

In [53]:
string.value


Out[53]:
'Konfoo'

In [54]:
bytes(string)


Out[54]:
b'Konfoo'

In [55]:
bytes(string).hex()


Out[55]:
'4b6f6e666f6f'

In [56]:
string.hex()


Out[56]:
'4b6f6e666f6f'

Serialize


In [57]:
buffer = bytearray()

In [58]:
string.value = 'Konfoo'

In [59]:
string.value = b'Konfoo'

In [60]:
string.serialize(buffer)


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

In [61]:
buffer.hex()


Out[61]:
'4b6f6e666f6f'

In [62]:
bytes(string).hex()


Out[62]:
'4b6f6e666f6f'

In [ ]: