Subversion Repositories HelenOS

Rev

Rev 3263 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3263 Rev 3264
Line 34... Line 34...
34
class Struct:
34
class Struct:
35
    def size(self):
35
    def size(self):
36
        return struct.calcsize(self._format_)
36
        return struct.calcsize(self._format_)
37
   
37
   
38
    def pack(self):
38
    def pack(self):
39
        list = []
39
        args = []
40
        for variable in self._list_:
40
        for variable in self._args_:
-
 
41
            if (isinstance(self.__dict__[variable], list)):
-
 
42
                for item in self.__dict__[variable]:
-
 
43
                    args.append(item)
-
 
44
            else:
41
            list.append(self.__dict__[variable])
45
                args.append(self.__dict__[variable])
42
       
46
       
43
        return struct.pack(self._format_, *list)
47
        return struct.pack(self._format_, *args)
44
 
48
 
45
def create(definition):
49
def create(definition):
46
    "Create structure object"
50
    "Create structure object"
47
   
51
   
48
    tokens = definition.split(None)
52
    tokens = definition.split(None)
Line 52... Line 56...
52
        "little:":  lambda: "<",
56
        "little:":  lambda: "<",
53
        "big:":     lambda: ">",
57
        "big:":     lambda: ">",
54
        "network:": lambda: "!"
58
        "network:": lambda: "!"
55
    }[tokens[0]]()
59
    }[tokens[0]]()
56
    inst = Struct()
60
    inst = Struct()
57
    list = []
61
    args = []
58
   
62
   
59
    # Member tags
63
    # Member tags
60
    comment = False
64
    comment = False
61
    variable = None
65
    variable = None
62
    for token in tokens[1:]:
66
    for token in tokens[1:]:
Line 76... Line 80...
76
                format += "%d" % int(subtokens[1].split("]")[0])
80
                format += "%d" % int(subtokens[1].split("]")[0])
77
           
81
           
78
            format += variable
82
            format += variable
79
           
83
           
80
            inst.__dict__[subtokens[0]] = None
84
            inst.__dict__[subtokens[0]] = None
81
            list.append(subtokens[0])
85
            args.append(subtokens[0])
82
           
86
           
83
            variable = None
87
            variable = None
84
            continue
88
            continue
85
       
89
       
86
        if (token[0:8] == "padding["):
90
        if (token[0:8] == "padding["):
Line 100... Line 104...
100
            "int32_t":  lambda: "l",
104
            "int32_t":  lambda: "l",
101
            "int64_t":  lambda: "q"
105
            "int64_t":  lambda: "q"
102
        }[token]()
106
        }[token]()
103
   
107
   
104
    inst.__dict__['_format_'] = format
108
    inst.__dict__['_format_'] = format
105
    inst.__dict__['_list_'] = list
109
    inst.__dict__['_args_'] = args
106
    return inst
110
    return inst