from bproto_base import bproto_Bitfield class HcpBitfieldEnables(bproto_Bitfield): BYTE_SIZE = 1 def __init__(self, a=False, b=False, c=False, ): self.a = a self.b = b self.c = c def to_bytes(self) -> bytes: res = 0 res |= (1 << 0) if self.a else 0 res |= (1 << 1) if self.b else 0 res |= (1 << 3) if self.c else 0 return int.to_bytes(res, self.BYTE_SIZE, 'little') def from_bytes(self, data: bytes): bits = int.from_bytes(data[:self.BYTE_SIZE], 'little') self.a = (bits & (1 << 0)) != 0 self.b = (bits & (1 << 1)) != 0 self.c = (bits & (1 << 3)) != 0 return self def __repr__(self) -> str: value_str = ", ".join([ "a=" + str(self.a), "b=" + str(self.b), "c=" + str(self.c), ]) return "HcpBitfieldEnables(" + value_str + ")" class HcpBitfieldInlineErrorEnables(bproto_Bitfield): BYTE_SIZE = 1 def __init__(self, test=False, asd=False, b=False, c=False, aa=False, ): self.test = test self.asd = asd self.b = b self.c = c self.aa = aa def to_bytes(self) -> bytes: res = 0 res |= (1 << 0) if self.test else 0 res |= (1 << 1) if self.asd else 0 res |= (1 << 2) if self.b else 0 res |= (1 << 3) if self.c else 0 res |= (1 << 7) if self.aa else 0 return int.to_bytes(res, self.BYTE_SIZE, 'little') def from_bytes(self, data: bytes): bits = int.from_bytes(data[:self.BYTE_SIZE], 'little') self.test = (bits & (1 << 0)) != 0 self.asd = (bits & (1 << 1)) != 0 self.b = (bits & (1 << 2)) != 0 self.c = (bits & (1 << 3)) != 0 self.aa = (bits & (1 << 7)) != 0 return self def __repr__(self) -> str: value_str = ", ".join([ "test=" + str(self.test), "asd=" + str(self.asd), "b=" + str(self.b), "c=" + str(self.c), "aa=" + str(self.aa), ]) return "HcpBitfieldInlineErrorEnables(" + value_str + ")"