Skip to main content

Encode a packet and inspect a validation finding

Native SDK. Start with the built example from Getting started. Append --roundtrip to its run command. For example, from examples/go on Linux run go run . ../../lib/misb0601.so ../../example.klv --roundtrip.

Each example encodes tag 2 (timestamp) and tag 3 (mission ID) as a revision 19 packet. The encoder writes the version and checksum. Decode the result and look for "3":"SURVEY". Use the full packet when validating real input. Here the example deliberately removes its last byte to produce a finding you can recognize.

The example driver calls this helper when you supply the flag.

examples/c/roundtrip.h
#pragma once
#include "misb0601.h"
#include <stdio.h>

static int roundtrip(void) {
uint8_t input[] = "{\"2\":1700000000000000,\"3\":\"SURVEY\"}";
misb0601_buffer packet = {0}, fields = {0}, report = {0};
int ok = Misb0601EncodeJSON(input, sizeof(input)-1, MISB0601_REVISION_19,
MISB0601_SORT_BY_TAG, &packet) == MISB0601_STATUS_OK;
if (ok) ok = Misb0601DecodeJSON(packet.data, packet.len, MISB0601_SORT_BY_TAG,
MISB0601_JSON_KEYS_TAGS, MISB0601_JSON_COMPACT, MISB0601_TIMESTAMPS_RAW, &fields) == MISB0601_STATUS_OK;
if (ok) ok = Misb0601ValidatePacket(packet.data, packet.len - 1, NULL, &report) == MISB0601_STATUS_OK;
if (ok) {
fwrite(fields.data, 1, fields.len, stdout);
putchar('\n');
fwrite(report.data, 1, report.len, stdout);
putchar('\n');
}
Misb0601BufferFree(&report);
Misb0601BufferFree(&fields);
Misb0601BufferFree(&packet);
return ok;
}

The report has valid: false. The first finding has rule ID packet-decode, severity error, and a message identifying the packet decode failure. The C and C++ examples print the JSON report. The C#, Go, and Python examples print the verdict followed by each finding. A successful validation call means a report was produced. Use its valid field to decide whether to accept the packet.