def decode(cls, data: BytesIO): name = ByteUtils.read_utf8(data) count = ByteUtils.read_uint8(data) neighbors = [] for _ in range(count): neighbors.append(MeshAddress(ByteUtils.read_uint16(data))) return cls(name=name, neighbors=neighbors)
def encode(self, data: BytesIO): ByteUtils.write_uint16(data, self.node.id) ByteUtils.write_int8(data, self.epoch) ByteUtils.write_uint8(data, len(self.link_nodes)) for node, epoch in zip(self.link_nodes, self.link_epochs): ByteUtils.write_uint16(data, node.id) ByteUtils.write_int8(data, epoch)
def decode(cls, data: BytesIO): source = ByteUtils.read_uint8(data) dest = ByteUtils.read_uint8(data) length = ByteUtils.read_uint16(data) checksum = ByteUtils.read_uint16(data) return cls(source=source, destination=dest, length=length, checksum=checksum)
def decode(cls, data: BytesIO): node = MeshAddress(ByteUtils.read_uint16(data)) name = ByteUtils.read_utf8(data) epoch = ByteUtils.read_int8(data) count = ByteUtils.read_uint8(data) link_states = [] for _ in range(count): link_states.append(LinkStateHeader.decode(data)) return cls(node=node, name=name, epoch=epoch, link_states=link_states)
def decode(cls, data: BytesIO): b = ByteUtils.read_uint8(data) is_request = bool(ByteUtils.hi_bits(b, 1)) control_type = ControlType(ByteUtils.lo_bits(b, 7)) extra_length = ByteUtils.read_uint8(data) extra = data.read(extra_length) return cls(is_request=is_request, control_type=control_type, extra_length=extra_length, extra=extra)
def decode(cls, data: BytesIO): byte = ByteUtils.read_int8(data) protocol = ByteUtils.hi_bits(byte, 4) flags = ByteUtils.lo_bits(byte, 4) fragment = ByteUtils.read_uint8(data) sequence = ByteUtils.read_uint16(data) return cls(protocol=Protocol(protocol), flags=FragmentFlags(flags), fragment=fragment, sequence=sequence)
def decode(cls, data: BytesIO): source = ByteUtils.read_uint16(data) port = ByteUtils.read_uint8(data) seq = ByteUtils.read_uint16(data) length = ByteUtils.read_uint16(data) checksum = ByteUtils.read_uint16(data) return cls(source=MeshAddress(source), port=port, sequence=seq, length=length, checksum=checksum)
def decode(cls, data: BytesIO): node = MeshAddress(ByteUtils.read_uint16(data)) epoch = ByteUtils.read_int8(data) count = ByteUtils.read_uint8(data) link_nodes = [] link_epochs = [] for _ in range(count): link_nodes.append(MeshAddress(ByteUtils.read_uint16(data))) link_epochs.append(ByteUtils.read_int8(data)) return cls(node=node, epoch=epoch, link_nodes=link_nodes, link_epochs=link_epochs)
def encode(self, data: BytesIO): ByteUtils.write_uint16(data, self.node.id) ByteUtils.write_utf8(data, self.name) ByteUtils.write_int8(data, self.epoch) ByteUtils.write_uint8(data, len(self.link_states)) for link_state in self.link_states: link_state.encode(data)
def decode(cls, data: BytesIO): byte = ByteUtils.read_int8(data) version = ByteUtils.hi_bits(byte, 4) protocol = ByteUtils.lo_bits(byte, 4) byte = ByteUtils.read_int8(data) qos = ByteUtils.hi_bits(byte, 3) ttl = ByteUtils.lo_bits(byte, 5) identity = ByteUtils.read_uint16(data) length = ByteUtils.read_uint16(data) source = ByteUtils.read_uint16(data) dest = ByteUtils.read_uint16(data) return cls(version=version, protocol=Protocol(protocol), qos=qos, ttl=ttl, identity=identity, length=length, source=MeshAddress(source), destination=MeshAddress(dest))
def encode(self, data: BytesIO): ByteUtils.write_uint8(data, self.source) ByteUtils.write_uint8(data, self.destination) ByteUtils.write_uint16(data, self.length) ByteUtils.write_uint16(data, self.checksum)
def encode(self, data: BytesIO): ByteUtils.write_utf8(data, self.name) ByteUtils.write_uint8(data, len(self.neighbors)) for neighbor in self.neighbors: ByteUtils.write_uint16(data, neighbor.id)
def encode(self, data: BytesIO): ByteUtils.write_uint16(data, self.source.id) ByteUtils.write_uint8(data, self.port) ByteUtils.write_uint16(data, self.sequence) ByteUtils.write_uint16(data, self.length) ByteUtils.write_uint16(data, self.checksum)
def encode(self, data: BytesIO): ByteUtils.write_hi_lo(data, self.protocol, self.flags, 4) ByteUtils.write_uint16(data, self.sequence)
def decode(cls, data: BytesIO): byte = ByteUtils.read_int8(data) protocol = ByteUtils.hi_bits(byte, 4) flags = ReliableFlags(ByteUtils.lo_bits(byte, 4)) seq = ByteUtils.read_uint16(data) return cls(protocol=protocol, flags=flags, sequence=seq)
def encode(self, data: BytesIO) -> None: ByteUtils.write_uint8(data, self.record_type.value) ByteUtils.write_uint8(data, self.length) data.write(self.value)
def encode(self, data: BytesIO): ByteUtils.write_hi_lo(data, int(self.is_request), self.control_type.value, 1) ByteUtils.write_uint8(data, self.extra_length) data.write(self.extra)
def decode(cls, data: BytesIO): node = MeshAddress(ByteUtils.read_uint16(data)) via = MeshAddress(ByteUtils.read_uint16(data)) quality = ByteUtils.read_uint8(data) return cls(node=node, via=via, quality=quality)
def encode(self, data: BytesIO): ByteUtils.write_uint16(data, self.node.id) ByteUtils.write_uint16(data, self.via.id) ByteUtils.write_uint8(data, self.quality)
def encode(self, data: BytesIO): ByteUtils.write_hi_lo(data, self.version, self.protocol, 4) ByteUtils.write_hi_lo(data, self.qos, self.ttl, 3) ByteUtils.write_uint16(data, self.identity) ByteUtils.write_uint16(data, self.length) ByteUtils.write_uint16(data, self.source.id) ByteUtils.write_uint16(data, self.destination.id)
def decode(cls, data: BytesIO): record_type = RecordType(ByteUtils.read_uint8(data)) length = ByteUtils.read_uint8(data) value = data.read(length) return cls(record_type=record_type, length=length, value=value)