# Path: tools/imports/shockabsorber/loader/util.py
# class SeqBuffer:  #------------------------------
#     def __init__(self,src, is_little_endian=False):
#     def readTag(self):
#     def unpack(self,be_fmt, le_fmt=None):
#     def unpackString8(self):
#     def unpackVarint(self):
#     def readBytes(self, len):
#     def tell(self):
#     def seek(self,new_offset):
#     def pread_from_to(self, frm, to):
#     def bytes_left(self):
#     def peek_bytes_left(self):
#     def at_eof(self):
# def rev(s):
# def half_expect(actual_value, expected_value, name):


from .util import SeqBuffer, rev, half_expect, int_struct, double_struct
from shockabsorber.model.scripts import ScriptNames
    lscr_sections = []
    for i in range(nEntries):
        sid = read_entry()
        if sid != -1: lscr_sections.append(sid)

    return (lnam_section_id, lscr_sections)

def parse_lnam_section(blob):
    buf = SeqBuffer(blob)
    [v1,v2,len1,len2,v3,numElems] = buf.unpack(">iiiiHH")
    names = []
    for i in range(numElems):
        names.append(buf.unpackString8())
    name_map = {} # For better printing
    for i in range(numElems):
        name_map[i] = names[i]
    return ScriptNames(names, [v1,v2,len1,len2,v3])
#--------------------------------------------------

def parse_lscr_section(snr, blob, names):
    print "DB| Lscr section #%d:" % (snr,)
    buf = SeqBuffer(blob)
    [v1,v2,totalLength,totalLength2,
     header_length, script_id, count2] = buf.unpack('>4i3H')
    [v3,v4,v5,v6,v7,v8,v9,v10,hvec_length] = buf.unpack('>6ihhh')
    [hvec_offset, flags56, props_count, props_offset, globs_count, globs_offset] = buf.unpack('>iiHiHi')
    [handler_count, handler_offset] = buf.unpack('>Hi')
    [literal_count, literal_offsets_offset, literals_length, literals_offset] = buf.unpack('>Hiii')
    half_expect(v1, 0, "Lscr.v1")
    half_expect(v2, 0, "Lscr.v2")

# Path: tools/imports/shockabsorber/loader/util.py
# class SeqBuffer:  #------------------------------
#     def __init__(self,src, is_little_endian=False):
#     def readTag(self):
#     def unpack(self,be_fmt, le_fmt=None):
#     def unpackString8(self):
#     def unpackVarint(self):
#     def readBytes(self, len):
#     def tell(self):
#     def seek(self,new_offset):
#     def pread_from_to(self, frm, to):
#     def bytes_left(self):
#     def peek_bytes_left(self):
#     def at_eof(self):
# def rev(s):
# def half_expect(actual_value, expected_value, name):


# Path: tools/imports/shockabsorber/loader/script_parser.py
from .util import SeqBuffer, rev, half_expect, int_struct, double_struct
from shockabsorber.model.scripts import ScriptNames

    lscr_sections = []
    for i in range(nEntries):
        sid = read_entry()
        if sid != -1: lscr_sections.append(sid)

    return (lnam_section_id, lscr_sections)

def parse_lnam_section(blob):
    buf = SeqBuffer(blob)
    [v1,v2,len1,len2,v3,numElems] = buf.unpack(">iiiiHH")
    names = []
    for i in range(numElems):
        names.append(buf.unpackString8())
    name_map = {} # For better printing
    for i in range(numElems):
        name_map[i] = names[i]
    return ScriptNames(names, [v1,v2,len1,len2,v3])
#--------------------------------------------------

def parse_lscr_section(snr, blob, names):
    print "DB| Lscr section #%d:" % (snr,)
    buf = SeqBuffer(blob)
    [v1,v2,totalLength,totalLength2,
     header_length, script_id, count2] = buf.unpack('>4i3H')
    [v3,v4,v5,v6,v7,v8,v9,v10,hvec_length] = buf.unpack('>6ihhh')
    [hvec_offset, flags56, props_count, props_offset, globs_count, globs_offset] = buf.unpack('>iiHiHi')
    [handler_count, handler_offset] = buf.unpack('>Hi')
    [literal_count, literal_offsets_offset, literals_length, literals_offset] = buf.unpack('>Hiii')
    half_expect(v1, 0, "Lscr.v1")
    half_expect(v2, 0, "Lscr.v2")

    half_expect(totalLength2, totalLength, "Lscr.totalLength2")