In [1]:
import json
import sys
from konfoo import *
In [2]:
import oyaml as yaml
In [3]:
def to_yaml(container, *attributes, **options):
flow_style = options.pop('flow_style', False)
return yaml.safe_dump(container.view_fields(*attributes, **options),
stream=sys.stdout,
default_flow_style=flow_style)
In [4]:
sequence = Sequence([Byte(), Unsigned8(), Decimal8(), Char()])
In [5]:
sequence.to_list()
Out[5]:
In [6]:
sequence.to_csv()
Out[6]:
In [7]:
sequence.to_json()
Out[7]:
In [8]:
to_yaml(sequence, flow_style=False)
In [9]:
sequence = Sequence()
In [10]:
sequence.append(Unsigned8())
In [11]:
sequence.to_list()
Out[11]:
In [12]:
sequence.to_csv()
Out[12]:
In [13]:
sequence.to_json()
Out[13]:
In [14]:
to_yaml(sequence, flow_style=False)
In [15]:
sequence.insert(0, Byte())
In [16]:
sequence.to_list()
Out[16]:
In [17]:
sequence.to_csv()
Out[17]:
In [18]:
sequence.to_json()
Out[18]:
In [19]:
to_yaml(sequence, flow_style=False)
In [20]:
sequence.extend([Decimal8(), Char()])
In [21]:
sequence.to_list()
Out[21]:
In [22]:
sequence.to_csv()
Out[22]:
In [23]:
sequence.to_json()
Out[23]:
In [24]:
to_yaml(sequence, flow_style=False)
In [25]:
sequence.initialize_fields([1, 2, 9, 'F'])
In [26]:
sequence.to_list()
Out[26]:
In [27]:
sequence.to_csv()
Out[27]:
In [28]:
sequence.to_json()
Out[28]:
In [29]:
to_yaml(sequence, flow_style=False)
In [30]:
sequence
Out[30]:
In [31]:
sequence.describe()
Out[31]:
In [32]:
json.dump(sequence.describe(), sys.stdout, indent=2)
In [33]:
d3flare_json(sequence.describe(), sys.stdout, indent=2)
In [34]:
sequence.container_size()
Out[34]:
In [35]:
num_of_bytes, num_of_remaining_bits = sequence.container_size()
In [36]:
num_of_bytes
Out[36]:
In [37]:
num_of_remaining_bits
Out[37]:
In [38]:
sequence.to_list('index')
Out[38]:
In [39]:
sequence.to_csv('index.byte', 'index.bit', 'index.address', fieldnames=('id', 'index', 'offset', 'address'))
Out[39]:
In [40]:
sequence.to_json('index')
Out[40]:
In [41]:
sequence.index_fields(index=Index())
Out[41]:
In [42]:
sequence.index_fields()
Out[42]:
In [43]:
sequence.to_list('index')
Out[43]:
In [44]:
sequence.to_csv('index.byte', 'index.bit', 'index.address', fieldnames=('id', 'index', 'offset', 'address'))
Out[44]:
In [45]:
sequence.to_json('index')
Out[45]:
In [46]:
sequence.deserialize(bytes.fromhex('01020946f00f00'))
Out[46]:
In [47]:
sequence.to_list()
Out[47]:
In [48]:
sequence.to_csv()
Out[48]:
In [49]:
sequence.to_json()
Out[49]:
In [50]:
to_yaml(sequence, flow_style=False)
In [51]:
bytestream = bytearray()
bytestream.hex()
Out[51]:
In [52]:
sequence.serialize(bytestream)
Out[52]:
In [53]:
bytes(sequence).hex()
Out[53]:
In [54]:
bytestream.hex()
Out[54]:
In [55]:
len(sequence)
Out[55]:
In [56]:
sequence[0]
Out[56]:
In [57]:
sequence[0].name
Out[57]:
In [58]:
sequence[0].value
Out[58]:
In [59]:
sequence[0].bit_size
Out[59]:
In [60]:
sequence[0].alignment
Out[60]:
In [61]:
sequence[0].alignment.byte_size
Out[61]:
In [62]:
sequence[0].alignment.bit_offset
Out[62]:
In [63]:
sequence[0].byte_order
Out[63]:
In [64]:
sequence[0].byte_order.value
Out[64]:
In [65]:
sequence[0].index
Out[65]:
In [66]:
sequence[0].index.byte
Out[66]:
In [67]:
sequence[0].index.bit
Out[67]:
In [68]:
sequence[0].index.address
Out[68]:
In [69]:
sequence[0].index.base_address
Out[69]:
In [70]:
sequence[0].index.update
Out[70]:
In [71]:
[member.item_type for member in sequence]
Out[71]:
In [72]:
sequence.view_fields()
Out[72]:
In [73]:
sequence.view_fields('name', 'bit_size', 'value', 'index', 'alignment', 'byte_order.name')
Out[73]:
In [74]:
sequence.to_json()
Out[74]:
In [75]:
print(sequence.to_json(indent=2))
In [76]:
sequence.to_json('name', 'bit_size', 'value', 'index', 'alignment', 'byte_order')
Out[76]:
In [77]:
print(sequence.to_json('name', 'bit_size', 'value', 'index', 'alignment', 'byte_order', indent=2))
In [78]:
sequence.field_items()
Out[78]:
In [79]:
sequence.to_list()
Out[79]:
In [80]:
sequence.to_list('name', 'bit_size', 'value', 'index', 'alignment', 'byte_order')
Out[80]:
In [81]:
sequence.to_dict()
Out[81]:
In [82]:
sequence.to_dict('name', 'bit_size', 'value', 'index', 'alignment', 'byte_order')
Out[82]:
In [83]:
sequence.to_csv()
Out[83]:
In [84]:
sequence.to_csv('name', 'bit_size', 'value', fieldnames=('id', 'type', 'size', 'value'))
Out[84]:
In [85]:
sequence.write_csv('Sequence.csv', 'name', 'bit_size', 'value', fieldnames=('id', 'type', 'size', 'value'))
In [86]:
sequence.save('Sequence.ini')
In [87]:
sequence.load('Sequence.ini')
In [ ]: