Example #1
0
	def unpack(cls, data):
		values = {}
		property_index = -1
		list_items = []
		while True:
			mask, data = Short.unpack(data)
			mask = mask.value
			for bit in range(15, 0, -1):
				property_index += 1
				if not mask & (1 << bit):
					continue
				if property_index >= len(cls.property_map):
					raise ValueError("Property bit out of range for {}".format(cls.__name__))
				name, datatype = cls.property_map[property_index]
				if datatype == PropertyBit:
					# special case for PropertyBit - if present, it means True, no list entry
					values[name] = True
					continue
				list_items.append((name, datatype))
			if not mask & 1:
				break
		for name, datatype in list_items:
			value, data = datatype.unpack(data)
			values[name] = value
		return cls(values), data
Example #2
0
 def unpack(cls, data):
     method_class, data = Short.unpack(data)
     method_id, data = Short.unpack(data)
     method_type = Method.from_id(method_class.value, method_id.value)
     method, data = method_type.unpack(data)
     return cls(method), data