# Path: mcm/librouteros/exceptions.py
# class ConnError( LibError ):
#     '''
#     Connection related errors.
#     '''


from socket import SHUT_RDWR, error as SOCKET_ERROR, timeout as SOCKET_TIMEOUT
from struct import pack, unpack
from mcm.librouteros.exceptions import ConnError
# -*- coding: UTF-8 -*-





def enclen( length ):
    '''
    Encode given length in mikrotik format.

    length: Integer < 268435456.
    returns: Encoded length in bytes.
    '''

    if length < 128:
        ored_length = length
        offset = -1
    elif length < 16384:
        ored_length = length | 0x8000
        offset = -2
    elif length < 2097152:
        ored_length = length | 0xC00000
        offset = -3
    elif length < 268435456:
        ored_length = length | 0xE0000000
        offset = -4
    else:

# Path: mcm/librouteros/exceptions.py
# class ConnError( LibError ):
#     '''
#     Connection related errors.
#     '''


# Path: mcm/librouteros/connections.py
from socket import SHUT_RDWR, error as SOCKET_ERROR, timeout as SOCKET_TIMEOUT
from struct import pack, unpack
from mcm.librouteros.exceptions import ConnError

# -*- coding: UTF-8 -*-





def enclen( length ):
    '''
    Encode given length in mikrotik format.

    length: Integer < 268435456.
    returns: Encoded length in bytes.
    '''

    if length < 128:
        ored_length = length
        offset = -1
    elif length < 16384:
        ored_length = length | 0x8000
        offset = -2
    elif length < 2097152:
        ored_length = length | 0xC00000
        offset = -3
    elif length < 268435456:
        ored_length = length | 0xE0000000
        offset = -4
    else:

        raise ConnError( 'unable to encode length of {}'