Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 1 | # Copyright (c) 2008 The Board of Trustees of The Leland Stanford Junior University |
| 2 | # Copyright (c) 2011, 2012 Open Networking Foundation |
| 3 | # Copyright (c) 2012, 2013 Big Switch Networks, Inc. |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 4 | # See the file LICENSE.pyloxi which should have been included in the source distribution |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 5 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 6 | # Automatically generated by LOXI from template module.py |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 7 | # Do not modify |
| 8 | |
| 9 | import struct |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 10 | import loxi |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 11 | import const |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 12 | import common |
| 13 | import action |
| 14 | import instruction |
| 15 | import oxm |
| 16 | import action_id |
| 17 | import instruction_id |
| 18 | import meter_band |
Rich Lane | 5454b68 | 2014-01-14 17:07:36 -0800 | [diff] [blame] | 19 | import bsn_tlv |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 20 | import util |
| 21 | import loxi.generic_util |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 22 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 23 | class instruction(loxi.OFObject): |
| 24 | subtypes = {} |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 25 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 26 | @staticmethod |
| 27 | def unpack(reader): |
| 28 | subtype, = reader.peek('!H', 0) |
| 29 | try: |
| 30 | subclass = instruction.subtypes[subtype] |
| 31 | except KeyError: |
| 32 | raise loxi.ProtocolError("unknown instruction subtype %#x" % subtype) |
| 33 | return subclass.unpack(reader) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 34 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 35 | |
| 36 | class apply_actions(instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 37 | type = 4 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 38 | |
| 39 | def __init__(self, actions=None): |
| 40 | if actions != None: |
| 41 | self.actions = actions |
| 42 | else: |
| 43 | self.actions = [] |
| 44 | return |
| 45 | |
| 46 | def pack(self): |
| 47 | packed = [] |
| 48 | packed.append(struct.pack("!H", self.type)) |
| 49 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 50 | packed.append('\x00' * 4) |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 51 | packed.append(loxi.generic_util.pack_list(self.actions)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 52 | length = sum([len(x) for x in packed]) |
| 53 | packed[1] = struct.pack("!H", length) |
| 54 | return ''.join(packed) |
| 55 | |
| 56 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 57 | def unpack(reader): |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 58 | obj = apply_actions() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 59 | _type = reader.read("!H")[0] |
| 60 | assert(_type == 4) |
| 61 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 62 | orig_reader = reader |
| 63 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 64 | reader.skip(4) |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 65 | obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 66 | return obj |
| 67 | |
| 68 | def __eq__(self, other): |
| 69 | if type(self) != type(other): return False |
| 70 | if self.actions != other.actions: return False |
| 71 | return True |
| 72 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 73 | def pretty_print(self, q): |
| 74 | q.text("apply_actions {") |
| 75 | with q.group(): |
| 76 | with q.indent(2): |
| 77 | q.breakable() |
| 78 | q.text("actions = "); |
| 79 | q.pp(self.actions) |
| 80 | q.breakable() |
| 81 | q.text('}') |
| 82 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 83 | instruction.subtypes[4] = apply_actions |
| 84 | |
| 85 | class experimenter(instruction): |
| 86 | subtypes = {} |
| 87 | |
| 88 | @staticmethod |
| 89 | def unpack(reader): |
| 90 | subtype, = reader.peek('!L', 4) |
| 91 | try: |
| 92 | subclass = experimenter.subtypes[subtype] |
| 93 | except KeyError: |
| 94 | raise loxi.ProtocolError("unknown experimenter instruction subtype %#x" % subtype) |
| 95 | return subclass.unpack(reader) |
| 96 | |
| 97 | instruction.subtypes[65535] = experimenter |
| 98 | |
| 99 | class bsn(experimenter): |
| 100 | subtypes = {} |
| 101 | |
| 102 | @staticmethod |
| 103 | def unpack(reader): |
| 104 | subtype, = reader.peek('!L', 8) |
| 105 | try: |
| 106 | subclass = bsn.subtypes[subtype] |
| 107 | except KeyError: |
| 108 | raise loxi.ProtocolError("unknown bsn experimenter instruction subtype %#x" % subtype) |
| 109 | return subclass.unpack(reader) |
| 110 | |
| 111 | experimenter.subtypes[6035143] = bsn |
| 112 | |
Rich Lane | 5454b68 | 2014-01-14 17:07:36 -0800 | [diff] [blame] | 113 | class bsn_arp_offload(bsn): |
| 114 | type = 65535 |
| 115 | experimenter = 6035143 |
| 116 | subtype = 1 |
| 117 | |
| 118 | def __init__(self): |
| 119 | return |
| 120 | |
| 121 | def pack(self): |
| 122 | packed = [] |
| 123 | packed.append(struct.pack("!H", self.type)) |
| 124 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 125 | packed.append(struct.pack("!L", self.experimenter)) |
| 126 | packed.append(struct.pack("!L", self.subtype)) |
| 127 | packed.append('\x00' * 4) |
| 128 | length = sum([len(x) for x in packed]) |
| 129 | packed[1] = struct.pack("!H", length) |
| 130 | return ''.join(packed) |
| 131 | |
| 132 | @staticmethod |
| 133 | def unpack(reader): |
| 134 | obj = bsn_arp_offload() |
| 135 | _type = reader.read("!H")[0] |
| 136 | assert(_type == 65535) |
| 137 | _len = reader.read("!H")[0] |
| 138 | orig_reader = reader |
| 139 | reader = orig_reader.slice(_len - (2 + 2)) |
| 140 | _experimenter = reader.read("!L")[0] |
| 141 | assert(_experimenter == 6035143) |
| 142 | _subtype = reader.read("!L")[0] |
| 143 | assert(_subtype == 1) |
| 144 | reader.skip(4) |
| 145 | return obj |
| 146 | |
| 147 | def __eq__(self, other): |
| 148 | if type(self) != type(other): return False |
| 149 | return True |
| 150 | |
| 151 | def pretty_print(self, q): |
| 152 | q.text("bsn_arp_offload {") |
| 153 | with q.group(): |
| 154 | with q.indent(2): |
| 155 | q.breakable() |
| 156 | q.breakable() |
| 157 | q.text('}') |
| 158 | |
| 159 | bsn.subtypes[1] = bsn_arp_offload |
| 160 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 161 | class bsn_disable_src_mac_check(bsn): |
Rich Lane | 7b0f201 | 2013-11-22 14:15:26 -0800 | [diff] [blame] | 162 | type = 65535 |
| 163 | experimenter = 6035143 |
| 164 | subtype = 0 |
| 165 | |
| 166 | def __init__(self): |
| 167 | return |
| 168 | |
| 169 | def pack(self): |
| 170 | packed = [] |
| 171 | packed.append(struct.pack("!H", self.type)) |
| 172 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 173 | packed.append(struct.pack("!L", self.experimenter)) |
| 174 | packed.append(struct.pack("!L", self.subtype)) |
| 175 | packed.append('\x00' * 4) |
| 176 | length = sum([len(x) for x in packed]) |
| 177 | packed[1] = struct.pack("!H", length) |
| 178 | return ''.join(packed) |
| 179 | |
| 180 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 181 | def unpack(reader): |
Rich Lane | 7b0f201 | 2013-11-22 14:15:26 -0800 | [diff] [blame] | 182 | obj = bsn_disable_src_mac_check() |
Rich Lane | 7b0f201 | 2013-11-22 14:15:26 -0800 | [diff] [blame] | 183 | _type = reader.read("!H")[0] |
| 184 | assert(_type == 65535) |
| 185 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 186 | orig_reader = reader |
| 187 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | 7b0f201 | 2013-11-22 14:15:26 -0800 | [diff] [blame] | 188 | _experimenter = reader.read("!L")[0] |
| 189 | assert(_experimenter == 6035143) |
| 190 | _subtype = reader.read("!L")[0] |
| 191 | assert(_subtype == 0) |
| 192 | reader.skip(4) |
| 193 | return obj |
| 194 | |
| 195 | def __eq__(self, other): |
| 196 | if type(self) != type(other): return False |
| 197 | return True |
| 198 | |
Rich Lane | 7b0f201 | 2013-11-22 14:15:26 -0800 | [diff] [blame] | 199 | def pretty_print(self, q): |
| 200 | q.text("bsn_disable_src_mac_check {") |
| 201 | with q.group(): |
| 202 | with q.indent(2): |
| 203 | q.breakable() |
| 204 | q.breakable() |
| 205 | q.text('}') |
| 206 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 207 | bsn.subtypes[0] = bsn_disable_src_mac_check |
| 208 | |
| 209 | class clear_actions(instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 210 | type = 5 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 211 | |
| 212 | def __init__(self): |
| 213 | return |
| 214 | |
| 215 | def pack(self): |
| 216 | packed = [] |
| 217 | packed.append(struct.pack("!H", self.type)) |
| 218 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 219 | packed.append('\x00' * 4) |
| 220 | length = sum([len(x) for x in packed]) |
| 221 | packed[1] = struct.pack("!H", length) |
| 222 | return ''.join(packed) |
| 223 | |
| 224 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 225 | def unpack(reader): |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 226 | obj = clear_actions() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 227 | _type = reader.read("!H")[0] |
| 228 | assert(_type == 5) |
| 229 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 230 | orig_reader = reader |
| 231 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 232 | reader.skip(4) |
| 233 | return obj |
| 234 | |
| 235 | def __eq__(self, other): |
| 236 | if type(self) != type(other): return False |
| 237 | return True |
| 238 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 239 | def pretty_print(self, q): |
| 240 | q.text("clear_actions {") |
| 241 | with q.group(): |
| 242 | with q.indent(2): |
| 243 | q.breakable() |
| 244 | q.breakable() |
| 245 | q.text('}') |
| 246 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 247 | instruction.subtypes[5] = clear_actions |
| 248 | |
| 249 | class goto_table(instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 250 | type = 1 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 251 | |
| 252 | def __init__(self, table_id=None): |
| 253 | if table_id != None: |
| 254 | self.table_id = table_id |
| 255 | else: |
| 256 | self.table_id = 0 |
| 257 | return |
| 258 | |
| 259 | def pack(self): |
| 260 | packed = [] |
| 261 | packed.append(struct.pack("!H", self.type)) |
| 262 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 263 | packed.append(struct.pack("!B", self.table_id)) |
| 264 | packed.append('\x00' * 3) |
| 265 | length = sum([len(x) for x in packed]) |
| 266 | packed[1] = struct.pack("!H", length) |
| 267 | return ''.join(packed) |
| 268 | |
| 269 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 270 | def unpack(reader): |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 271 | obj = goto_table() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 272 | _type = reader.read("!H")[0] |
| 273 | assert(_type == 1) |
| 274 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 275 | orig_reader = reader |
| 276 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 277 | obj.table_id = reader.read("!B")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 278 | reader.skip(3) |
| 279 | return obj |
| 280 | |
| 281 | def __eq__(self, other): |
| 282 | if type(self) != type(other): return False |
| 283 | if self.table_id != other.table_id: return False |
| 284 | return True |
| 285 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 286 | def pretty_print(self, q): |
| 287 | q.text("goto_table {") |
| 288 | with q.group(): |
| 289 | with q.indent(2): |
| 290 | q.breakable() |
| 291 | q.text("table_id = "); |
| 292 | q.text("%#x" % self.table_id) |
| 293 | q.breakable() |
| 294 | q.text('}') |
| 295 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 296 | instruction.subtypes[1] = goto_table |
| 297 | |
| 298 | class meter(instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 299 | type = 6 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 300 | |
| 301 | def __init__(self, meter_id=None): |
| 302 | if meter_id != None: |
| 303 | self.meter_id = meter_id |
| 304 | else: |
| 305 | self.meter_id = 0 |
| 306 | return |
| 307 | |
| 308 | def pack(self): |
| 309 | packed = [] |
| 310 | packed.append(struct.pack("!H", self.type)) |
| 311 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 312 | packed.append(struct.pack("!L", self.meter_id)) |
| 313 | length = sum([len(x) for x in packed]) |
| 314 | packed[1] = struct.pack("!H", length) |
| 315 | return ''.join(packed) |
| 316 | |
| 317 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 318 | def unpack(reader): |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 319 | obj = meter() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 320 | _type = reader.read("!H")[0] |
| 321 | assert(_type == 6) |
| 322 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 323 | orig_reader = reader |
| 324 | reader = orig_reader.slice(_len - (2 + 2)) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 325 | obj.meter_id = reader.read("!L")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 326 | return obj |
| 327 | |
| 328 | def __eq__(self, other): |
| 329 | if type(self) != type(other): return False |
| 330 | if self.meter_id != other.meter_id: return False |
| 331 | return True |
| 332 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 333 | def pretty_print(self, q): |
| 334 | q.text("meter {") |
| 335 | with q.group(): |
| 336 | with q.indent(2): |
| 337 | q.breakable() |
| 338 | q.text("meter_id = "); |
| 339 | q.text("%#x" % self.meter_id) |
| 340 | q.breakable() |
| 341 | q.text('}') |
| 342 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 343 | instruction.subtypes[6] = meter |
| 344 | |
| 345 | class write_actions(instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 346 | type = 3 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 347 | |
| 348 | def __init__(self, actions=None): |
| 349 | if actions != None: |
| 350 | self.actions = actions |
| 351 | else: |
| 352 | self.actions = [] |
| 353 | return |
| 354 | |
| 355 | def pack(self): |
| 356 | packed = [] |
| 357 | packed.append(struct.pack("!H", self.type)) |
| 358 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 359 | packed.append('\x00' * 4) |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 360 | packed.append(loxi.generic_util.pack_list(self.actions)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 361 | length = sum([len(x) for x in packed]) |
| 362 | packed[1] = struct.pack("!H", length) |
| 363 | return ''.join(packed) |
| 364 | |
| 365 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 366 | def unpack(reader): |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 367 | obj = write_actions() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 368 | _type = reader.read("!H")[0] |
| 369 | assert(_type == 3) |
| 370 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 371 | orig_reader = reader |
| 372 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 373 | reader.skip(4) |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 374 | obj.actions = loxi.generic_util.unpack_list(reader, action.action.unpack) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 375 | return obj |
| 376 | |
| 377 | def __eq__(self, other): |
| 378 | if type(self) != type(other): return False |
| 379 | if self.actions != other.actions: return False |
| 380 | return True |
| 381 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 382 | def pretty_print(self, q): |
| 383 | q.text("write_actions {") |
| 384 | with q.group(): |
| 385 | with q.indent(2): |
| 386 | q.breakable() |
| 387 | q.text("actions = "); |
| 388 | q.pp(self.actions) |
| 389 | q.breakable() |
| 390 | q.text('}') |
| 391 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 392 | instruction.subtypes[3] = write_actions |
| 393 | |
| 394 | class write_metadata(instruction): |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 395 | type = 2 |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 396 | |
| 397 | def __init__(self, metadata=None, metadata_mask=None): |
| 398 | if metadata != None: |
| 399 | self.metadata = metadata |
| 400 | else: |
| 401 | self.metadata = 0 |
| 402 | if metadata_mask != None: |
| 403 | self.metadata_mask = metadata_mask |
| 404 | else: |
| 405 | self.metadata_mask = 0 |
| 406 | return |
| 407 | |
| 408 | def pack(self): |
| 409 | packed = [] |
| 410 | packed.append(struct.pack("!H", self.type)) |
| 411 | packed.append(struct.pack("!H", 0)) # placeholder for len at index 1 |
| 412 | packed.append('\x00' * 4) |
| 413 | packed.append(struct.pack("!Q", self.metadata)) |
| 414 | packed.append(struct.pack("!Q", self.metadata_mask)) |
| 415 | length = sum([len(x) for x in packed]) |
| 416 | packed[1] = struct.pack("!H", length) |
| 417 | return ''.join(packed) |
| 418 | |
| 419 | @staticmethod |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 420 | def unpack(reader): |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 421 | obj = write_metadata() |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 422 | _type = reader.read("!H")[0] |
| 423 | assert(_type == 2) |
| 424 | _len = reader.read("!H")[0] |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 425 | orig_reader = reader |
| 426 | reader = orig_reader.slice(_len - (2 + 2)) |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 427 | reader.skip(4) |
Dan Talayco | f620225 | 2013-07-02 01:00:29 -0700 | [diff] [blame] | 428 | obj.metadata = reader.read("!Q")[0] |
| 429 | obj.metadata_mask = reader.read("!Q")[0] |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 430 | return obj |
| 431 | |
| 432 | def __eq__(self, other): |
| 433 | if type(self) != type(other): return False |
| 434 | if self.metadata != other.metadata: return False |
| 435 | if self.metadata_mask != other.metadata_mask: return False |
| 436 | return True |
| 437 | |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 438 | def pretty_print(self, q): |
| 439 | q.text("write_metadata {") |
| 440 | with q.group(): |
| 441 | with q.indent(2): |
| 442 | q.breakable() |
| 443 | q.text("metadata = "); |
| 444 | q.text("%#x" % self.metadata) |
| 445 | q.text(","); q.breakable() |
| 446 | q.text("metadata_mask = "); |
| 447 | q.text("%#x" % self.metadata_mask) |
| 448 | q.breakable() |
| 449 | q.text('}') |
| 450 | |
Rich Lane | 7dcdf02 | 2013-12-11 14:45:27 -0800 | [diff] [blame] | 451 | instruction.subtypes[2] = write_metadata |
Rich Lane | ca3da27 | 2013-05-05 09:07:33 -0700 | [diff] [blame] | 452 | |
Rich Lane | 7b0f201 | 2013-11-22 14:15:26 -0800 | [diff] [blame] | 453 | |