Changes in tools/xstruct.py [a35b458:1b20da0] in mainline


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/xstruct.py

    ra35b458 r1b20da0  
    7272        def size(self):
    7373                return struct.calcsize(self._format_)
    74 
     74       
    7575        def pack(self):
    7676                args = []
     
    9090                                args.append(value)
    9191                return struct.pack(self._format_, *args)
    92 
     92       
    9393        def unpack(self, data):
    9494                values = struct.unpack(self._format_, data)
     
    100100def create(definition):
    101101        "Create structure object"
    102 
     102       
    103103        tokens = definition.split(None)
    104 
     104       
    105105        # Initial byte order tag
    106106        format = {
     
    111111        inst = Struct()
    112112        args = []
    113 
     113       
    114114        # Member tags
    115115        comment = False
     
    120120                                comment = False
    121121                        continue
    122 
     122               
    123123                if (token == "/*"):
    124124                        comment = True
    125125                        continue
    126 
     126               
    127127                if (variable != None):
    128128                        subtokens = token.split("[")
    129 
     129                       
    130130                        length = None
    131131                        if (len(subtokens) > 1):
    132132                                length = int(subtokens[1].split("]")[0])
    133133                                format += "%d" % length
    134 
     134                       
    135135                        format += variable
    136 
     136                       
    137137                        inst.__dict__[subtokens[0]] = None
    138138                        args.append((subtokens[0], variable, length))
    139 
     139                       
    140140                        variable = None
    141141                        continue
    142 
     142               
    143143                if (token[0:8] == "padding["):
    144144                        size = token[8:].split("]")[0]
    145145                        format += "%dx" % int(size)
    146146                        continue
    147 
     147               
    148148                variable = {
    149149                        "char":     lambda: "s",
     
    152152                        "uint32_t": lambda: "L",
    153153                        "uint64_t": lambda: "Q",
    154 
     154                       
    155155                        "int8_t":   lambda: "b",
    156156                        "int16_t":  lambda: "h",
     
    158158                        "int64_t":  lambda: "q"
    159159                }[token]()
    160 
     160       
    161161        inst.__dict__['_format_'] = format
    162162        inst.__dict__['_args_'] = args
Note: See TracChangeset for help on using the changeset viewer.