def encode_remainining_length(remaining_length):
    # type: (int) -> bytes
    """Encode the remaining length for the packet.

    :returns: Encoded remaining length
    :rtype: bytes
    """
    encoding = True
    encoded_bytes = bytearray()
    encoded_byte = 0
    while encoding:
        encoded_byte = remaining_length % 128
        remaining_length //= 128
        if remaining_length:
            encoded_byte |= 0x80
        else:
            encoding = False
        encoded_bytes.append(encoded_byte)
    return bytes(encoded_bytes)