Skip to main content

Decode your first native packet

Open your installed SDK directory or extract the portable native ZIP. Run the archive-root commands below from that directory. Keep lib/, examples/, and example.klv together. Start with no token set. For a web application, follow the browser and Node.js quickstart.

The sample ST 0601 packet​

The examples below decode this 87-byte MISB ST 0601 revision 19 packet, supplied as example.klv.

Hex dump of the ST 0601 sample packet, from the 16-byte key through the checksum 68 9C
Open the full-size hex dump
  • Key. The first 16 bytes, 06 0E 2B 34 02 0B 01 01 0E 01 03 01 01 00 00 00, identify the ST 0601 UAS Datalink Local Set.
  • Length. The next byte, 46 in hexadecimal, is the BER length. It declares 70 bytes of value, including the checksum item.
  • Value. The local set contains tag-length-value items. For example, 41 01 13 means tag 65 has a one-byte value of 0x13, which identifies revision 19. Tag 3 carries Test mission and tag 10 carries Test platform.
  • Checksum. The last item is 01 02 68 9C. Tag 1 has a two-byte checksum value of 0x689C (26780), computed over the packet bytes through 01 02.

Select a language below. The Go, Java, and Python commands use the Windows filename misb0601.dll. On Linux use misb0601.so. On macOS use misb0601.dylib.

From the extracted archive root, use the command pair for your platform. Putting the executable beside the library lets it find the runtime.

C commands
# Windows x64 (MinGW)
gcc -Iinclude examples/c/example.c lib/misb0601.dll -o lib/read.exe
./lib/read.exe example.klv
# Linux x64
cc -Iinclude examples/c/example.c lib/misb0601.so -Wl,-rpath,'$ORIGIN' -o lib/read
./lib/read example.klv
# macOS arm64
cc -Iinclude examples/c/example.c lib/misb0601.dylib -Wl,-rpath,@loader_path -o lib/read
./lib/read example.klv
examples/c/example.c
#include <stdio.h>
#include <stdlib.h>
#include "misb0601.h"
#include "roundtrip.h"
#include "fields.h"
#include "stream.h"
#include <string.h>

// Read a complete sample file without silently accepting a prefix.
static int read_sample(const char *path, uint8_t *buffer, size_t capacity, size_t *size) {
FILE *file = fopen(path, "rb");
if (!file) {
perror(path);
return 0;
}
*size = fread(buffer, 1, capacity, file);
int complete = fgetc(file) == EOF && !ferror(file);
fclose(file);
if (!complete) fprintf(stderr, "Could not read the complete sample file %s\n", path);
return complete;
}

int main(int argc, char **argv) {
if (argc < 2) return 1;
int encode = argc >= 3 && strcmp(argv[2], "--roundtrip") == 0;
if (encode && argc != 4) {
fputs("Usage: read <packet.klv> --roundtrip <input.json>\n", stderr);
return 1;
}

uint8_t packet[65536];
size_t size;
if (!read_sample(argv[1], packet, sizeof(packet), &size)) return 1;

// Validate the optional license token and report the decoder mode.
misb0601_license_status license = {0};
Misb0601LicenseInitialize(getenv("LIBMISB_NATIVE_TOKEN"), &license);
puts(license.is_decoder_demo ? "demo" : "licensed");

// Decode the complete KLV buffer to tag-keyed JSON with raw integer timestamps.
// Both OK and PARTIAL can return JSON that the caller must free.
misb0601_buffer json = {0};
int status = Misb0601DecodeJSON(packet, size, MISB0601_SORT_BY_TAG, MISB0601_JSON_KEYS_TAGS,
MISB0601_JSON_COMPACT, MISB0601_TIMESTAMPS_RAW, &json);
if (json.len) fwrite(json.data, 1, json.len, stdout);
putchar('\n');
Misb0601BufferFree(&json);

// Run the requested follow-up example, if any.
if (argc == 3 && strcmp(argv[2], "--fields") == 0) read_fields(packet, size);
int extra_ok = 1;
if (encode) {
uint8_t input[65536];
size_t input_size;
extra_ok = read_sample(argv[3], input, sizeof(input), &input_size) && roundtrip(input, input_size);
}
if (argc == 3 && strcmp(argv[2], "--stream") == 0) extra_ok = stream_packet(packet, size);
Misb0601LicenseShutdown();
return !extra_ok || (status != MISB0601_STATUS_OK && status != MISB0601_STATUS_PARTIAL);
}

Recognize the result​

The first line is demo. The next line contains these fields. Key order and whitespace may vary.

{
"1": 9400,
"2": 1795433587745520,
"3": "Test mission",
"4": "24",
"5": 147.9991,
"10": "Test platform",
"13": 41.093374324,
"14": -104.868772498,
"65": 19
}

Tag 2 is the precision timestamp in microseconds. Demo mode omits sensor true altitude (tag 15) and reports a checksum of 9400 for the filtered packet. A licensed decode includes tag 15 and reports the original checksum 26780.

The native SDK also includes example.json with the full sample fields used in the encoding and validation walkthrough. See reading fields to extract the timestamp and version in code.

How decoding works​

An MQ-9 Reaper illustrates the STANAG 4609 source. The SDK decodes extracted KLV packets as ST 0601 timestamps, position, and sensor data.

Complete KLV packet or stream chunks
↓
KLV framing and parsing
↓
ST 0601 revision-aware decoding
↓
Decoded fields and diagnostics
  1. Supply the bytes. Pass a complete packet to the packet API, or feed successive chunks to a stream that assembles packets across chunk boundaries. For media input, pass the PES payload extracted by your demultiplexer. If available, pass its presentation timestamp (PTS) separately from the timestamp carried inside the metadata.
  2. Read the KLV envelope. The parser reads the key, length, and value. Raw KLV operations give applications access to packet and item structure. ST 0601 operations interpret the local set carried in the packet value.
  3. Decode using the applicable revision. The decoder can use the version in tag 65 to select field definitions. It interprets values and nested metadata, such as security or VMTI, according to the applicable definitions.
  4. Consume the result. Check the status and diagnostic before using the fields. A partial result can contain usable fields alongside a recoverable error. When sending large integers through JavaScript, keep the exact JSON text or use an integer-preserving parser.

Complete packets and fragmented input​

Complete packet. Use the packet API when you already have one complete KLV packet, such as example.klv. Pass its key, BER length, and entire value together in one call.

Fragmented input. For MPEG-TS, use a demultiplexer to select the KLV metadata stream by PID and extract its packetized elementary stream (PES) payload bytes. Feed the payload chunks in order to one libmisb stream decoder. Supply the presentation timestamp (PTS) separately when it is available. PTS identifies a time on the media timeline. ST 0601 tag 2 carries the metadata's own timestamp.

libmisb uses the KLV key and BER length to frame each packet. If the first chunk ends inside packet A, the decoder holds those bytes. If the next chunk finishes A and starts B, the decoder emits A and keeps the start of B for the next push. A push can yield zero, one, or several packets.

Packet decoding takes the key, BER length, and value together. In the stream example, the first PES payload chunk starts packet A. The second finishes A and starts B, so the stream decodes A and buffers B.

Flush the stream at end of input to detect a truncated final packet. For native streams, poll for events after each push and after flushing. On the web, callbacks run during push and flush.

Decode fragmented packets and PES payloads · Revisions, exact JSON, and partial results