class Unpacker:

    def __init__(self, settings):
        self._settings = settings

    def parse_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)

        len_key = int.from_bytes(
            package[1:1 + self._settings.len_len_key], "big")
        key = package[1 + self._settings.len_len_key:
                      1 + self._settings.len_len_key + len_key]

        len_value_start = 1 + self._settings.len_len_key +\
            self._settings.max_len_key
        len_value_end = 1 + self._settings.len_len_key +\
            self._settings.max_len_key +\
            self._settings.len_len_value
        len_value = int.from_bytes(
            package[len_value_start: len_value_end], "big")

        value_start = 1 + self._settings.len_len_key +\
            self._settings.max_len_key +\
            self._settings.len_len_value
        value_end = 1 + self._settings.len_len_key +\
            self._settings.max_len_key +\
            self._settings.len_len_value + len_value
        value = package[value_start: value_end]

        str_key = key.decode(self._settings.encoding)
        str_value = value.decode(self._settings.encoding)

        return str_command, str_key, str_value

    def parse_number_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)

        if str_command != "n":
            return
        return int.from_bytes(package[1:5], "big")

    def parse_get_keys_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)

        if str_command != "f":
            return
        return package[1:2]

    def parse_count_keys_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)

        if str_command != "c":
            return None, None
        number = package[1:2]
        count = int.from_bytes(package[2:6], "big")
        return number, count

    def parse_keys_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)

        if str_command != "k":
            return None, None

        number = package[1:2]
        count = int.from_bytes(package[2:3], "big")

        keys = []
        for i in range(count):
            start = 3 + 257 * i
            len_key = int.from_bytes(
                package[start:start + self._settings.len_len_key], "big")
            key = package[start + self._settings.len_len_key:
                          start + self._settings.len_len_key + len_key]
            keys.append(key.decode(self._settings.encoding)[1:])
        return number, keys

    def parse_command(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)

        return command

    def parse_number_data(self, package):
        return package[1:2]

9b3b5edcdae4a90d92738a8f14b0e6fbbb0605e2
class Unpacker:
    <mask token>
    <mask token>
    <mask token>

    def parse_get_keys_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)
        if str_command != 'f':
            return
        return package[1:2]

    def parse_count_keys_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)
        if str_command != 'c':
            return None, None
        number = package[1:2]
        count = int.from_bytes(package[2:6], 'big')
        return number, count

    def parse_keys_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)
        if str_command != 'k':
            return None, None
        number = package[1:2]
        count = int.from_bytes(package[2:3], 'big')
        keys = []
        for i in range(count):
            start = 3 + 257 * i
            len_key = int.from_bytes(package[start:start + self._settings.
                len_len_key], 'big')
            key = package[start + self._settings.len_len_key:start + self.
                _settings.len_len_key + len_key]
            keys.append(key.decode(self._settings.encoding)[1:])
        return number, keys
    <mask token>

    def parse_number_data(self, package):
        return package[1:2]

class Unpacker:
    <mask token>
    <mask token>
    <mask token>

    def parse_get_keys_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)
        if str_command != 'f':
            return
        return package[1:2]

    def parse_count_keys_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)
        if str_command != 'c':
            return None, None
        number = package[1:2]
        count = int.from_bytes(package[2:6], 'big')
        return number, count

    def parse_keys_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)
        if str_command != 'k':
            return None, None
        number = package[1:2]
        count = int.from_bytes(package[2:3], 'big')
        keys = []
        for i in range(count):
            start = 3 + 257 * i
            len_key = int.from_bytes(package[start:start + self._settings.
                len_len_key], 'big')
            key = package[start + self._settings.len_len_key:start + self.
                _settings.len_len_key + len_key]
            keys.append(key.decode(self._settings.encoding)[1:])
        return number, keys

    def parse_command(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)
        return command

    def parse_number_data(self, package):
        return package[1:2]

class Unpacker:

    def __init__(self, settings):
        self._settings = settings
    <mask token>
    <mask token>

    def parse_get_keys_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)
        if str_command != 'f':
            return
        return package[1:2]

    def parse_count_keys_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)
        if str_command != 'c':
            return None, None
        number = package[1:2]
        count = int.from_bytes(package[2:6], 'big')
        return number, count

    def parse_keys_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)
        if str_command != 'k':
            return None, None
        number = package[1:2]
        count = int.from_bytes(package[2:3], 'big')
        keys = []
        for i in range(count):
            start = 3 + 257 * i
            len_key = int.from_bytes(package[start:start + self._settings.
                len_len_key], 'big')
            key = package[start + self._settings.len_len_key:start + self.
                _settings.len_len_key + len_key]
            keys.append(key.decode(self._settings.encoding)[1:])
        return number, keys

    def parse_command(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)
        return command

    def parse_number_data(self, package):
        return package[1:2]

class Unpacker:

    def __init__(self, settings):
        self._settings = settings

    def parse_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)
        len_key = int.from_bytes(package[1:1 + self._settings.len_len_key],
            'big')
        key = package[1 + self._settings.len_len_key:1 + self._settings.
            len_len_key + len_key]
        len_value_start = (1 + self._settings.len_len_key + self._settings.
            max_len_key)
        len_value_end = (1 + self._settings.len_len_key + self._settings.
            max_len_key + self._settings.len_len_value)
        len_value = int.from_bytes(package[len_value_start:len_value_end],
            'big')
        value_start = (1 + self._settings.len_len_key + self._settings.
            max_len_key + self._settings.len_len_value)
        value_end = (1 + self._settings.len_len_key + self._settings.
            max_len_key + self._settings.len_len_value + len_value)
        value = package[value_start:value_end]
        str_key = key.decode(self._settings.encoding)
        str_value = value.decode(self._settings.encoding)
        return str_command, str_key, str_value

    def parse_number_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)
        if str_command != 'n':
            return
        return int.from_bytes(package[1:5], 'big')

    def parse_get_keys_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)
        if str_command != 'f':
            return
        return package[1:2]

    def parse_count_keys_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)
        if str_command != 'c':
            return None, None
        number = package[1:2]
        count = int.from_bytes(package[2:6], 'big')
        return number, count

    def parse_keys_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)
        if str_command != 'k':
            return None, None
        number = package[1:2]
        count = int.from_bytes(package[2:3], 'big')
        keys = []
        for i in range(count):
            start = 3 + 257 * i
            len_key = int.from_bytes(package[start:start + self._settings.
                len_len_key], 'big')
            key = package[start + self._settings.len_len_key:start + self.
                _settings.len_len_key + len_key]
            keys.append(key.decode(self._settings.encoding)[1:])
        return number, keys

    def parse_command(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)
        return command

    def parse_number_data(self, package):
        return package[1:2]

class Unpacker:

    def __init__(self, settings):
        self._settings = settings

    def parse_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)

        len_key = int.from_bytes(
            package[1:1 + self._settings.len_len_key], "big")
        key = package[1 + self._settings.len_len_key:
                      1 + self._settings.len_len_key + len_key]

        len_value_start = 1 + self._settings.len_len_key +\
            self._settings.max_len_key
        len_value_end = 1 + self._settings.len_len_key +\
            self._settings.max_len_key +\
            self._settings.len_len_value
        len_value = int.from_bytes(
            package[len_value_start: len_value_end], "big")

        value_start = 1 + self._settings.len_len_key +\
            self._settings.max_len_key +\
            self._settings.len_len_value
        value_end = 1 + self._settings.len_len_key +\
            self._settings.max_len_key +\
            self._settings.len_len_value + len_value
        value = package[value_start: value_end]

        str_key = key.decode(self._settings.encoding)
        str_value = value.decode(self._settings.encoding)

        return str_command, str_key, str_value

    def parse_number_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)

        if str_command != "n":
            return
        return int.from_bytes(package[1:5], "big")

    def parse_get_keys_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)

        if str_command != "f":
            return
        return package[1:2]

    def parse_count_keys_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)

        if str_command != "c":
            return None, None
        number = package[1:2]
        count = int.from_bytes(package[2:6], "big")
        return number, count

    def parse_keys_package(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)

        if str_command != "k":
            return None, None

        number = package[1:2]
        count = int.from_bytes(package[2:3], "big")

        keys = []
        for i in range(count):
            start = 3 + 257 * i
            len_key = int.from_bytes(
                package[start:start + self._settings.len_len_key], "big")
            key = package[start + self._settings.len_len_key:
                          start + self._settings.len_len_key + len_key]
            keys.append(key.decode(self._settings.encoding)[1:])
        return number, keys

    def parse_command(self, package):
        command = package[0:1]
        str_command = command.decode(self._settings.encoding)

        return command

    def parse_number_data(self, package):
        return package[1:2]
