Raw KLV C ABI
Load the platform's libmisb shared library and initialize it with LibmisbLicenseInitialize. Raw reads require the decode capability and writes require encode. Keys and item values are returned as bytes.
| Operation | Functions | Output owner |
|---|---|---|
| Decode a packet or locate one in a buffer | LibmisbKLVDecodePacket, LibmisbKLVFindPacket | LibmisbKLVPacketResultFree |
| Decode local-set items | LibmisbKLVDecodeLocalSet | LibmisbKLVItemResultFree |
| Build a packet or local-set value | LibmisbKLVEncodePacket, LibmisbKLVEncodeLocalSet | LibmisbBufferFree |
| Stream packets | LibmisbKLVStreamDecoderCreate, Push, Next, Flush (same decoder prefix) | LibmisbKLVStreamEventFree per event; LibmisbKLVStreamDecoderFree per handle |
For example, this Python function reads a three-byte local set with tag 15 and a one-byte value. Pass the raw library path and a native decode token.
from ctypes import byref, c_uint8
from misb0601 import raw_abi
def item_count(path, token):
lib = raw_abi.load(path)
status = raw_abi.libmisb_license_status()
lib.LibmisbLicenseInitialize(token.encode(), byref(status))
result = raw_abi.libmisb_klv_item_result()
try:
data = (c_uint8 * 3)(15, 1, 120)
code = lib.LibmisbKLVDecodeLocalSet(data, len(data), 0, byref(result))
if code != 0:
raise RuntimeError("raw local-set decode failed")
return result.item_count
finally:
lib.LibmisbKLVItemResultFree(byref(result))
lib.LibmisbLicenseShutdown()
The result's item table gives offsets and lengths within its payload buffer. Read them before freeing the result. For fixed one-byte tags, select the corresponding tag encoding from include/libmisb.h; BER-OID is the default.