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.

Select a language below. The C#, 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.

# 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>

int main(int argc, char **argv) {
if (argc < 2) return 1;
FILE *file = fopen(argv[1], "rb");
if (!file) return 1;
uint8_t packet[65536];
size_t size = fread(packet, 1, sizeof(packet), file);
int complete = fgetc(file) == EOF && !ferror(file);
fclose(file);
if (!complete) return 1;
misb0601_license_status license = {0};
Misb0601LicenseInitialize(getenv("LIBMISB_NATIVE_TOKEN"), &license);
puts(license.is_decoder_demo ? "demo" : "licensed");
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);
if (argc == 3 && strcmp(argv[2], "--fields") == 0) read_fields(packet, size);
int extra_ok = argc < 3 || strcmp(argv[2], "--roundtrip") != 0 || roundtrip();
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":23503,"2":9007199254740993,"65":19}

Tag 65 identifies revision 19. Tag 2 is a timestamp in microseconds. Tag 1 is the checksum. Continue to reading fields or encoding and validation.