-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTLV.py
More file actions
95 lines (70 loc) · 2.6 KB
/
TLV.py
File metadata and controls
95 lines (70 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
class TLV:
"""Contains general packet framework for the tlv-Value-Length format"""
def __init__(self, tlv_type, tlv_length=1024, tlv_value="test"):
"""
tlv - indicates sub tlv
for tlv number assignments refer http://named-data.net/doc/NDN-packet-spec/current/tlvs.html
:param tlv type: this is the type number of the tlv
:param tlv length: length of the tlv value
:param tlv value:
"""
#Todo: I am not sure whether this will be needed or not. If it is not needed remove this
self.__tlv = None
self.__tlv_type = tlv_type
self.__tlv_length = tlv_length
self.__tlv_value = tlv_value
def __str__(self):
"""
:return: string which contains tlv_number,length,value dict
"""
tlv_type = self.get_tlv_type()
tlv_length = self.get_tlv_length()
tlv_value = self.get_tlv_value()
res = {"tlv_type": tlv_type, "tlv_length": tlv_length, "tlv_value": tlv_value}
return str(res)
def get_tlv_type(self):
return self.__tlv_type
def get_tlv_length(self):
return self.__tlv_length
def get_tlv_value(self):
return self.__tlv_value
def get_tlv(self):
"""
Use this function whenever the tlv object is needed
It will return the tlv object as a dictionary of tlv_number,tlv_length,tlv_value
Loop through the dictionary to examine the contents of the tlv object
This method should be used by the users to examine or decompose the data
:return:
"""
tlv_type = self.get_tlv_type()
tlv_length = self.get_tlv_length()
tlv_value = self.get_tlv_value()
res = {"tlv_type": tlv_type, "tlv_length": tlv_length, "tlv_value": tlv_value}
return res
def get_sub_tlv(self):
"""
:return: returns the sub tlv which is nested in the current tlv
"""
return self.__tlv
def set_tlv_value(self,value):
"""
sets the tlv_value manually
:param value: this is the actual content generated by the producer
:return: None
"""
self.__tlv_value = value
def set_tlv(self,tlv):
"""
Todo: I am not sure whether this will be needed or not. If it is not needed remove this
assigns inner tlv for the current tlv
:param tlv: this is inner tlv
:return:
"""
self.__tlv = tlv
def get(self):
return self.get_tlv()
def get_value(self):
"""
:return: returns the tlv value
"""
return self.get_tlv_value()