# Path: pyisis/lib/util.py
# def cast_as (bufptr, ctype):
#     try:
#         return ctype.from_buffer(bufptr)
#     except TypeError:
#         return cast(bufptr, POINTER(ctype)).contents
# 
# def tlvrdb (val):
#     # In python3 byte strings return integers when indexed
#     return val


from ctypes import BigEndianStructure, create_string_buffer
from ctypes import c_uint8, c_uint16, c_uint32, sizeof
from pyisis.lib.util import cast_as, tlvrdb
import pyisis.clns as clns
import sys
        return PDU_FRAME_TYPE_LEVEL[pdu_type]
    except KeyError:
        return 0


def get_frame (pkt):
    if not pkt:
        return None
    frame = cast_as(pkt, CLNSEtherFrame)
    pdu_type = frame.clns_pdu_type
    try:
        return cast_as(pkt, PDU_FRAME_TYPES[pdu_type])
    except KeyError:
        return None


def get_raw_lsp_pdu (lindex):
    pdu_type = clns.PDU_TYPE_LSP_LX[lindex]
    lsp, buf, tlvview = get_pdu_buffer(clns.originatingLxLSPBufferSize(lindex), pdu_type)
    tlvview = memoryview(buf)[sizeof(lsp):]             # Get pointer to tlv space
    return lsp, buf, tlvview


def get_pdu_buffer (size, pdu_type):
    """Get a PDU buffer of the given size cast to the correct type"""
    if sys.version_info >= (3, 0):
        buf = bytearray(size)
        hdr = PDU_PDU_TYPES[pdu_type].from_buffer(buf)
    else:
        buf = create_string_buffer(size)

# Path: pyisis/lib/util.py
# def cast_as (bufptr, ctype):
#     try:
#         return ctype.from_buffer(bufptr)
#     except TypeError:
#         return cast(bufptr, POINTER(ctype)).contents
# 
# def tlvrdb (val):
#     # In python3 byte strings return integers when indexed
#     return val


# Path: pyisis/pdu.py
from ctypes import BigEndianStructure, create_string_buffer
from ctypes import c_uint8, c_uint16, c_uint32, sizeof
from pyisis.lib.util import cast_as, tlvrdb
import pyisis.clns as clns
import sys

        return PDU_FRAME_TYPE_LEVEL[pdu_type]
    except KeyError:
        return 0


def get_frame (pkt):
    if not pkt:
        return None
    frame = cast_as(pkt, CLNSEtherFrame)
    pdu_type = frame.clns_pdu_type
    try:
        return cast_as(pkt, PDU_FRAME_TYPES[pdu_type])
    except KeyError:
        return None


def get_raw_lsp_pdu (lindex):
    pdu_type = clns.PDU_TYPE_LSP_LX[lindex]
    lsp, buf, tlvview = get_pdu_buffer(clns.originatingLxLSPBufferSize(lindex), pdu_type)
    tlvview = memoryview(buf)[sizeof(lsp):]             # Get pointer to tlv space
    return lsp, buf, tlvview


def get_pdu_buffer (size, pdu_type):
    """Get a PDU buffer of the given size cast to the correct type"""
    if sys.version_info >= (3, 0):
        buf = bytearray(size)
        hdr = PDU_PDU_TYPES[pdu_type].from_buffer(buf)
    else:
        buf = create_string_buffer(size)

        hdr = cast_as(buf, PDU_PDU_TYPES[pdu_type])