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]:
class DataObject(Structure):
def __init__(self):
super().__init__()
self.size = Decimal(16)
self.item = Pointer()
self.index_fields()
In [5]:
data_object = DataObject()
In [6]:
data_object.to_list()
Out[6]:
In [7]:
data_object.to_csv()
Out[7]:
In [8]:
data_object.to_json()
Out[8]:
In [9]:
to_yaml(data_object, flow_style=False)
In [10]:
data_object.to_list(nested=True)
Out[10]:
In [11]:
data_object.to_csv(nested=True)
Out[11]:
In [12]:
data_object.to_json(nested=True)
Out[12]:
In [13]:
to_yaml(data_object, nested=True, flow_style=False)
In [14]:
class DataObjectPointer(Pointer):
def __init__(self, address=None, byte_order=BYTEORDER):
super().__init__(template=DataObject(),
address=address,
data_order=byte_order)
In [15]:
pointer = DataObjectPointer()
In [16]:
pointer.to_list()
Out[16]:
In [17]:
pointer.to_csv()
Out[17]:
In [18]:
pointer.to_json()
Out[18]:
In [19]:
to_yaml(pointer, flow_style=False)
In [20]:
pointer.to_list(nested=True)
Out[20]:
In [21]:
pointer.to_csv(nested=True)
Out[21]:
In [22]:
pointer.to_json(nested=True)
Out[22]:
In [23]:
to_yaml(pointer, nested=True, flow_style=False)
In [24]:
pointer = Pointer(Pointer())
In [25]:
pointer.to_list()
Out[25]:
In [26]:
pointer.to_csv()
Out[26]:
In [27]:
pointer.to_json()
Out[27]:
In [28]:
to_yaml(pointer, flow_style=False)
In [29]:
pointer.to_list(nested=True)
Out[29]:
In [30]:
pointer.to_csv(nested=True)
Out[30]:
In [31]:
pointer.to_json(nested=True)
Out[31]:
In [32]:
to_yaml(pointer, nested=True, flow_style=False)
In [33]:
pointer = Pointer(Pointer(Byte()))
In [34]:
pointer.to_list()
Out[34]:
In [35]:
pointer.to_csv()
Out[35]:
In [36]:
pointer.to_json()
Out[36]:
In [37]:
to_yaml(pointer, flow_style=False)
In [38]:
pointer.to_list(nested=True)
Out[38]:
In [39]:
pointer.to_csv(nested=True)
Out[39]:
In [40]:
pointer.to_json(nested=True)
Out[40]:
In [41]:
to_yaml(pointer, nested=True, flow_style=False)
In [42]:
pointer = Pointer(Pointer(Byte()))
In [43]:
pointer.data
Out[43]:
In [44]:
pointer.data.data
Out[44]:
In [45]:
pointer.address
Out[45]:
In [46]:
pointer.data_byte_order
Out[46]:
In [47]:
pointer.data_byte_order = 'big'
In [48]:
pointer.data_byte_order
Out[48]:
In [49]:
pointer.bytestream
Out[49]:
In [50]:
pointer.bytestream = '01020304'
In [51]:
pointer.bytestream
Out[51]:
In [52]:
pointer = Pointer(
Structure(
size=Decimal(16),
item=Pointer(String(14))))
In [53]:
pointer.to_list(nested=True)
Out[53]:
In [54]:
pointer.to_csv(nested=True)
Out[54]:
In [55]:
pointer.to_json(nested=True)
Out[55]:
In [56]:
to_yaml(pointer, nested=True, flow_style=False)
In [57]:
pointer.initialize_fields({
'value': 0x1,
'data': {
'size': 14,
'item': {'value': 0x10,
'data': 'Konfoo is Fun'}}})
In [58]:
pointer.to_list(nested=True)
Out[58]:
In [59]:
pointer.to_csv(nested=True)
Out[59]:
In [60]:
pointer.to_json(nested=True)
Out[60]:
In [61]:
to_yaml(pointer, nested=True, flow_style=False)
In [62]:
pointer = Pointer(
Structure(
size=Decimal(16),
item=Pointer(String())))
In [63]:
pointer.index_fields()
Out[63]:
In [64]:
pointer
Out[64]:
In [65]:
pointer.data
Out[65]:
In [66]:
pointer.describe()
Out[66]:
In [67]:
json.dump(pointer.describe(), sys.stdout, indent=2)
In [68]:
d3flare_json(pointer.describe(), sys.stdout, indent=2)
In [69]:
pointer.data_size
Out[69]:
In [70]:
pointer = Pointer(
Structure(
size=Decimal(16),
item=Pointer(String(14))))
In [71]:
pointer.initialize_fields({
'value': 0x1,
'data': {
'size': 14,
'item': {'value': 0x10,
'data': 'Konfoo is Fun'}}})
In [72]:
pointer.to_list('index', nested=True)
Out[72]:
In [73]:
pointer.to_csv('index.byte', 'index.bit', 'index.address', fieldnames=('id', 'index', 'offset', 'address'), nested=True)
Out[73]:
In [74]:
pointer.to_json('index', nested=True)
Out[74]:
In [75]:
pointer.index_fields(index=Index())
Out[75]:
In [76]:
pointer.index_fields()
Out[76]:
In [77]:
pointer.to_list('index', nested=True)
Out[77]:
In [78]:
pointer.to_csv('index.byte', 'index.bit', 'index.address', fieldnames=('id', 'index', 'offset', 'address'), nested=True)
Out[78]:
In [79]:
pointer.to_json('index', nested=True)
Out[79]:
In [80]:
pointer.index_fields(index=Index(), nested=True)
Out[80]:
In [81]:
pointer.index_fields(nested=True)
Out[81]:
In [82]:
pointer.to_list('index', nested=True)
Out[82]:
In [83]:
pointer.to_csv('index.byte', 'index.bit', 'index.address', fieldnames=('id', 'index', 'offset', 'address'), nested=True)
Out[83]:
In [84]:
pointer.to_json('index', nested=True)
Out[84]:
In [85]:
pointer = Pointer(
Structure(
size=Decimal(16),
item=Pointer(String(14))))
In [86]:
pointer.initialize_fields({
'value': 0x1,
'data': {
'size': 14,
'item': {'value': 0x10,
'data': 'Konfoo is Fun'}}})
In [87]:
pointer.to_list('index', nested=True)
Out[87]:
In [88]:
pointer.to_csv('index.byte', 'index.bit', 'index.address', fieldnames=('id', 'index', 'offset', 'address'), nested=True)
Out[88]:
In [89]:
pointer.to_json('index', nested=True)
Out[89]:
In [90]:
pointer.index_field(index=Index())
Out[90]:
In [91]:
pointer.index_field()
Out[91]:
In [92]:
pointer.to_list('index', nested=True)
Out[92]:
In [93]:
pointer.to_csv('index.byte', 'index.bit', 'index.address', fieldnames=('id', 'index', 'offset', 'address'), nested=True)
Out[93]:
In [94]:
pointer.to_json('index', nested=True)
Out[94]:
In [95]:
pointer = Pointer(
Structure(
size=Decimal(16),
item=Pointer(String())))
In [96]:
pointer.initialize_fields({
'value': 0x1,
'data': {
'size': 14,
'item': {'value': 0x10,
'data': 'Konfoo is Fun'}}})
In [97]:
pointer.to_list('index', nested=True)
Out[97]:
In [98]:
pointer.to_csv('index.byte', 'index.bit', 'index.address', fieldnames=('id', 'index', 'offset', 'address'), nested=True)
Out[98]:
In [99]:
pointer.to_json('index', nested=True)
Out[99]:
In [100]:
pointer.index_data()
In [101]:
pointer.to_list('index', nested=True)
Out[101]:
In [102]:
pointer.to_csv('index.byte', 'index.bit', 'index.address', fieldnames=('id', 'index', 'offset', 'address'), nested=True)
Out[102]:
In [103]:
pointer.to_json('index', nested=True)
Out[103]:
In [104]:
pointer = Pointer(
Structure(
size=Decimal(16),
item=Pointer(String(14))))
In [105]:
pointer.to_list(nested=True)
Out[105]:
In [106]:
pointer.to_csv(nested=True)
Out[106]:
In [107]:
pointer.to_json(nested=True)
Out[107]:
In [108]:
to_yaml(pointer, nested=True, flow_style=False)
In [109]:
pointer.bytestream
Out[109]:
In [110]:
pointer.data.item.bytestream
Out[110]:
In [111]:
pointer.deserialize(bytes.fromhex('010000000e00100000004b6f6e666f6f2069732046756e00f00f00'))
Out[111]:
In [112]:
pointer.to_list(nested=True)
Out[112]:
In [113]:
pointer.to_csv(nested=True)
Out[113]:
In [114]:
pointer.to_json(nested=True)
Out[114]:
In [115]:
to_yaml(pointer, nested=True, flow_style=False)
In [116]:
pointer.deserialize(bytes.fromhex('010000000e00100000004b6f6e666f6f2069732046756e00f00f00'), nested=True)
Out[116]:
In [117]:
pointer.to_list(nested=True)
Out[117]:
In [118]:
pointer.to_csv(nested=True)
Out[118]:
In [119]:
pointer.to_json(nested=True)
Out[119]:
In [120]:
to_yaml(pointer, nested=True, flow_style=False)
In [121]:
pointer.bytestream = '0e0010000000'
In [122]:
pointer.data.item.bytestream = '4b6f6e666f6f2069732046756e00f00f00'
In [123]:
pointer.deserialize(bytes.fromhex('01000000'))
Out[123]:
In [124]:
pointer.to_list(nested=True)
Out[124]:
In [125]:
pointer.to_csv(nested=True)
Out[125]:
In [126]:
pointer.to_json(nested=True)
Out[126]:
In [127]:
to_yaml(pointer, nested=True, flow_style=False)
In [128]:
pointer.deserialize(bytes.fromhex('01000000'), nested=True)
Out[128]:
In [129]:
pointer.to_list(nested=True)
Out[129]:
In [130]:
pointer.to_csv(nested=True)
Out[130]:
In [131]:
pointer.to_json(nested=True)
Out[131]:
In [132]:
to_yaml(pointer, nested=True, flow_style=False)
In [133]:
pointer = Pointer(
Structure(
size=Decimal(16),
item=Pointer(String(14))), 1)
In [134]:
pointer.to_list(nested=True)
Out[134]:
In [135]:
pointer.to_csv(nested=True)
Out[135]:
In [136]:
pointer.to_json(nested=True)
Out[136]:
In [137]:
to_yaml(pointer, nested=True, flow_style=False)
In [138]:
pointer.bytestream
Out[138]:
In [139]:
pointer.data.item.bytestream = '4b6f6e666f6f2069732046756e00'
In [140]:
pointer.deserialize_data(bytes.fromhex('0e0010000000'))
Out[140]:
In [141]:
pointer.bytestream
Out[141]:
In [142]:
pointer.to_list(nested=True)
Out[142]:
In [143]:
pointer.to_csv(nested=True)
Out[143]:
In [144]:
pointer.to_json(nested=True)
Out[144]:
In [145]:
to_yaml(pointer, nested=True, flow_style=False)
In [146]:
pointer.data.item.deserialize_data()
Out[146]:
In [147]:
pointer.to_list(nested=True)
Out[147]:
In [148]:
pointer.to_csv(nested=True)
Out[148]:
In [149]:
pointer.to_json(nested=True)
Out[149]:
In [150]:
to_yaml(pointer, nested=True, flow_style=False)
In [151]:
pointer.to_list(nested=True)
Out[151]:
In [152]:
pointer.to_csv(nested=True)
Out[152]:
In [153]:
pointer.to_json(nested=True)
Out[153]:
In [154]:
to_yaml(pointer, nested=True, flow_style=False)
In [155]:
pointer.bytestream = ''
pointer.bytestream
Out[155]:
In [156]:
pointer.data.item.bytestream = ''
pointer.data.item.bytestream
Out[156]:
In [157]:
bytestream = bytearray()
bytestream.hex()
Out[157]:
In [158]:
pointer.serialize(bytestream)
Out[158]:
In [159]:
pointer.bytestream
Out[159]:
In [160]:
pointer.data.item.bytestream
Out[160]:
In [161]:
bytes(pointer).hex()
Out[161]:
In [162]:
bytestream.hex()
Out[162]:
In [163]:
bytestream = bytearray()
bytestream.hex()
Out[163]:
In [164]:
pointer.serialize(bytestream, nested=True)
Out[164]:
In [165]:
pointer.bytestream
Out[165]:
In [166]:
pointer.data.item.bytestream
Out[166]:
In [167]:
bytes(pointer).hex()
Out[167]:
In [168]:
bytestream.hex()
Out[168]:
In [169]:
pointer.to_list(nested=True)
Out[169]:
In [170]:
pointer.to_csv(nested=True)
Out[170]:
In [171]:
pointer.to_json(nested=True)
Out[171]:
In [172]:
to_yaml(pointer, nested=True, flow_style=False)
In [173]:
pointer.bytestream = ''
pointer.bytestream
Out[173]:
In [174]:
pointer.data.item.bytestream = ''
pointer.data.item.bytestream
Out[174]:
In [175]:
pointer.serialize_data().hex()
Out[175]:
In [176]:
pointer.bytestream
Out[176]:
In [177]:
pointer.data.item.serialize_data().hex()
Out[177]:
In [178]:
pointer.data.item.bytestream
Out[178]:
In [179]:
pointer.data
Out[179]:
In [180]:
pointer.name
Out[180]:
In [181]:
pointer.value
Out[181]:
In [182]:
pointer.bit_size
Out[182]:
In [183]:
pointer.alignment
Out[183]:
In [184]:
pointer.alignment.byte_size
Out[184]:
In [185]:
pointer.alignment.bit_offset
Out[185]:
In [186]:
pointer.byte_order
Out[186]:
In [187]:
pointer.byte_order.value
Out[187]:
In [188]:
pointer.index
Out[188]:
In [189]:
pointer.index.byte
Out[189]:
In [190]:
pointer.index.bit
Out[190]:
In [191]:
pointer.index.address
Out[191]:
In [192]:
pointer.index.base_address
Out[192]:
In [193]:
pointer.index.update
Out[193]:
In [194]:
pointer.view_fields()
Out[194]:
In [195]:
pointer.view_fields(nested=True)
Out[195]:
In [196]:
pointer.view_fields('name', 'bit_size', 'value', 'index', 'alignment', 'byte_order.name')
Out[196]:
In [197]:
pointer.to_json()
Out[197]:
In [198]:
print(pointer.to_json(indent=2))
In [199]:
pointer.to_json(nested=True)
Out[199]:
In [200]:
print(pointer.to_json(nested=True, indent=2))
In [201]:
pointer.to_json('name', 'bit_size', 'value', 'index', 'alignment', 'byte_order')
Out[201]:
In [202]:
print(pointer.to_json('name', 'bit_size', 'value', 'index', 'alignment', 'byte_order', indent=2))
In [203]:
pointer.field_items()
Out[203]:
In [204]:
pointer.to_list()
Out[204]:
In [205]:
pointer.to_list(nested=True)
Out[205]:
In [206]:
pointer.to_list('name', 'bit_size', 'value', 'index', 'alignment', 'byte_order')
Out[206]:
In [207]:
pointer.to_dict()
Out[207]:
In [208]:
pointer.to_dict(nested=True)
Out[208]:
In [209]:
pointer.to_dict('name', 'bit_size', 'value', 'index', 'alignment', 'byte_order')
Out[209]:
In [210]:
pointer.to_csv()
Out[210]:
In [211]:
pointer.to_csv(nested=True)
Out[211]:
In [212]:
pointer.to_csv('name', 'bit_size', 'value', fieldnames=('id', 'type', 'size', 'value'), nested=True)
Out[212]:
In [213]:
pointer.write_csv('Pointer.csv', 'name', 'bit_size', 'value', fieldnames=('id', 'type', 'size', 'value'), nested=True)
In [214]:
pointer.save('Pointer.ini', nested=True)
In [215]:
pointer.load('Pointer.ini', nested=True)
In [ ]: