def encode(self, obj, signal): r = [] for k, v in sorted(self.fields.items()): start = v.byte*8+v.offset end = start+v.width field = self.get_field(obj, k, v.width) if self.swap_field_bytes: field = reverse_bytes(field) r.append(signal[start:end].eq(field)) return r
def decode(self, signal, obj): r = [] for k, v in sorted(self.fields.items()): start = v.byte*8+v.offset end = start+v.width field = self.get_field(obj, k, v.width) if self.swap_field_bytes: r.append(field.eq(reverse_bytes(signal[start:end]))) else: r.append(field.eq(signal[start:end])) return r