示例#1
0
    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
示例#2
0
 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)
示例#3
0
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
示例#4
0
def test_encode_bytes_count():
    assert len(encode(300)) == 2
示例#5
0
def test_encoding_length():
    for idx in range(0, 53):
        number = floor(pow(2, idx))
        assert len(encode(number)) == encoding_length(number)