# Path: dizzy/tools.py
# def check_root(text):
# def unique(seq, idfun=None):
#         def idfun(x): return x
# def read_with_length(data, length, endian='!'):
# def pack_with_length(value, size, endian='!'):
# def chr_to_bin(c):
# def str_to_bin(s):
# def shift_left(inp, by, out=None):
# def shift_right(inp, by, out=None):
# def csum_inet(data, csum=0):
# 
# Path: dizzy/value.py
# class Value(object):
#     def __init__(self, byte=b'', size=None):
#         if isinstance(byte, str):
#             from dizzy.config import CONFIG
#             byte = byte.encode(CONFIG["GLOBALS"]["CODEC"])
#         if isinstance(byte, bytes):
#             if size is None:
#                 self.byte = byte
#                 self.size = len(self.byte) * 8
#             elif isinstance(size, int):
#                 self.byte = format_bytes(byte, size)
#                 self.size = size
#             else:
#                 raise TypeError()
#         else:
#             raise TypeError()
#     
#     def __add__(self, other):
#         result = Value()
# 
#         if self.size == 0:
#             result.byte = format_bytes(copy(other.byte), other.size)
#             result.size = other.size
#         elif other.size == 0:
#             result.byte = format_bytes(copy(self.byte), self.size)
#             result.size = self.size
#         else:
#             result.byte = bytearray(format_bytes(other.byte, other.size))
#             mod = other.size % 8
# 
#             if mod == 0:
#                 result.byte = self.byte + result.byte
#             else:
#                 for x in reversed(self.byte):
#                     result.byte[0] |= (x << mod) & 0xff
#                     result.byte.insert(0, x >> (8 - mod))
# 
#             result.size = self.size + other.size
#             result.byte = bytes(format_bytes(result.byte, result.size))
# 
#         return result
# 
#     def __bytes__(self):
#         return self.byte
#     
#     def __repr__(self):
#         return "Value(%s, %d)" % (self.byte, self.size)
# 
#     def __len__(self):
#         return self.size
#     
#     def __eq__(self, other):
#         if not isinstance(other, Value):
#             return False
#         return self.byte == other.byte and self.size == other.size


from dizzy import tools
from dizzy.value import Value
        if libidx is None:
            if not obj["encoding"] is None:
                cur = obj["cur"].decode(obj["encoding"])
            else:
                cur = obj["cur"].decode(CONFIG["GLOBALS"]["CODEC"])
        else:
            cur = obj["cur"]
        if obj["_type"] == "list":
            libidx = obj["listname"]
        if not libidx in self.lib:
            self.gen_entries(libidx)
        if cur not in self.lib[libidx]:
            if libidx == None:
                return self.lib[libidx][0]
            return None
        return self.lib[libidx][self.lib[libidx].index(cur) + 1]

    def _get_next(self, index, cur):
        if not index in self.lib:
            self.gen_entries(index)
        if cur is None:
            return self.lib[index][0]
        return self.lib[index][self.lib[index].index(cur) + 1]

    def gen_entries(self, length):
        bytelen = length // 8
        if length % 8 > 0:
            bytelen += 1
        if length >= 4:
            entr = []

# Path: dizzy/tools.py
# def check_root(text):
# def unique(seq, idfun=None):
#         def idfun(x): return x
# def read_with_length(data, length, endian='!'):
# def pack_with_length(value, size, endian='!'):
# def chr_to_bin(c):
# def str_to_bin(s):
# def shift_left(inp, by, out=None):
# def shift_right(inp, by, out=None):
# def csum_inet(data, csum=0):
# 
# Path: dizzy/value.py
# class Value(object):
#     def __init__(self, byte=b'', size=None):
#         if isinstance(byte, str):
#             from dizzy.config import CONFIG
#             byte = byte.encode(CONFIG["GLOBALS"]["CODEC"])
#         if isinstance(byte, bytes):
#             if size is None:
#                 self.byte = byte
#                 self.size = len(self.byte) * 8
#             elif isinstance(size, int):
#                 self.byte = format_bytes(byte, size)
#                 self.size = size
#             else:
#                 raise TypeError()
#         else:
#             raise TypeError()
#     
#     def __add__(self, other):
#         result = Value()
# 
#         if self.size == 0:
#             result.byte = format_bytes(copy(other.byte), other.size)
#             result.size = other.size
#         elif other.size == 0:
#             result.byte = format_bytes(copy(self.byte), self.size)
#             result.size = self.size
#         else:
#             result.byte = bytearray(format_bytes(other.byte, other.size))
#             mod = other.size % 8
# 
#             if mod == 0:
#                 result.byte = self.byte + result.byte
#             else:
#                 for x in reversed(self.byte):
#                     result.byte[0] |= (x << mod) & 0xff
#                     result.byte.insert(0, x >> (8 - mod))
# 
#             result.size = self.size + other.size
#             result.byte = bytes(format_bytes(result.byte, result.size))
# 
#         return result
# 
#     def __bytes__(self):
#         return self.byte
#     
#     def __repr__(self):
#         return "Value(%s, %d)" % (self.byte, self.size)
# 
#     def __len__(self):
#         return self.size
#     
#     def __eq__(self, other):
#         if not isinstance(other, Value):
#             return False
#         return self.byte == other.byte and self.size == other.size


# Path: dizzy/library.py
from dizzy import tools
from dizzy.value import Value

        if libidx is None:
            if not obj["encoding"] is None:
                cur = obj["cur"].decode(obj["encoding"])
            else:
                cur = obj["cur"].decode(CONFIG["GLOBALS"]["CODEC"])
        else:
            cur = obj["cur"]
        if obj["_type"] == "list":
            libidx = obj["listname"]
        if not libidx in self.lib:
            self.gen_entries(libidx)
        if cur not in self.lib[libidx]:
            if libidx == None:
                return self.lib[libidx][0]
            return None
        return self.lib[libidx][self.lib[libidx].index(cur) + 1]

    def _get_next(self, index, cur):
        if not index in self.lib:
            self.gen_entries(index)
        if cur is None:
            return self.lib[index][0]
        return self.lib[index][self.lib[index].index(cur) + 1]

    def gen_entries(self, length):
        bytelen = length // 8
        if length % 8 > 0:
            bytelen += 1
        if length >= 4:
            entr = []

            entr += [tools.pack_with_length(0, length)]