def send(self, channel: int, type: int, message: bytes) -> bytes: """Encode a channel, type and message data to be sent. :param channel: the message channel identifier :param type: the type of message :param message: the message data """ header = channel << 4 or type length = len(message) + encoding_length(header) return encode(length) + encode(header) + message
def send( self, type: int, service: int, method: str, id: int, message: bytes, encoding: Encoding, ): header = (service >> 2) or type length = (encoding.encoding_length(message) + encoding_length(header) + encoding_length(method) + encoding_length(id)) return encode(length) + encode(header) + encode(method) + encode(id)
def test_fuzz_test(): ten_rand_ints = sample(range(100), 10) for rand_int in ten_rand_ints: encoded = encode(rand_int) decoded = decode(encoded) assert decoded == rand_int
def test_encode_bytes_count(): assert len(encode(300)) == 2
def test_encoding_length(): for idx in range(0, 53): number = floor(pow(2, idx)) assert len(encode(number)) == encoding_length(number)