Changeset a35b458 in mainline for tools/xstruct.py
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/xstruct.py
r3061bc1 ra35b458 72 72 def size(self): 73 73 return struct.calcsize(self._format_) 74 74 75 75 def pack(self): 76 76 args = [] … … 90 90 args.append(value) 91 91 return struct.pack(self._format_, *args) 92 92 93 93 def unpack(self, data): 94 94 values = struct.unpack(self._format_, data) … … 100 100 def create(definition): 101 101 "Create structure object" 102 102 103 103 tokens = definition.split(None) 104 104 105 105 # Initial byte order tag 106 106 format = { … … 111 111 inst = Struct() 112 112 args = [] 113 113 114 114 # Member tags 115 115 comment = False … … 120 120 comment = False 121 121 continue 122 122 123 123 if (token == "/*"): 124 124 comment = True 125 125 continue 126 126 127 127 if (variable != None): 128 128 subtokens = token.split("[") 129 129 130 130 length = None 131 131 if (len(subtokens) > 1): 132 132 length = int(subtokens[1].split("]")[0]) 133 133 format += "%d" % length 134 134 135 135 format += variable 136 136 137 137 inst.__dict__[subtokens[0]] = None 138 138 args.append((subtokens[0], variable, length)) 139 139 140 140 variable = None 141 141 continue 142 142 143 143 if (token[0:8] == "padding["): 144 144 size = token[8:].split("]")[0] 145 145 format += "%dx" % int(size) 146 146 continue 147 147 148 148 variable = { 149 149 "char": lambda: "s", … … 152 152 "uint32_t": lambda: "L", 153 153 "uint64_t": lambda: "Q", 154 154 155 155 "int8_t": lambda: "b", 156 156 "int16_t": lambda: "h", … … 158 158 "int64_t": lambda: "q" 159 159 }[token]() 160 160 161 161 inst.__dict__['_format_'] = format 162 162 inst.__dict__['_args_'] = args
Note:
See TracChangeset
for help on using the changeset viewer.