Skip to main content

Read the timestamp and version

In the native quickstart, the decoder returns tag-keyed JSON. Read tag 2 as an unsigned 64-bit integer and tag 65 as the packet version. The supplied packet has values 9007199254740993 and 19. Fields are sparse: check for presence before using a value.

ST 0601 packet diagram showing the precision timestamp (tag 2), version (tag 65), and checksum (tag 1)
Open the full-size ST 0601 packet diagram

Append --fields to the run command from the quickstart. For example, on Linux run ./lib/read example.klv --fields with the C executable. The final line reads 9007199254740993 19.

examples/c/fields.h
#include <inttypes.h>
#include <stdio.h>
#include "misb0601_typed.h"

static void read_fields(uint8_t *packet, size_t size) {
misb0601_tag_value_result tags = {0};
int rc = Misb0601DecodeTagValues(packet, size, MISB0601_SORT_BY_TAG, &tags);
if (rc == MISB0601_STATUS_OK || rc == MISB0601_STATUS_PARTIAL) {
misb0601_local_set fields;
if (misb0601_local_set_from_tag_values(&tags, &fields)) {
uint64_t timestamp;
uint8_t version;
if (misb0601_local_set_try_get_uint64(&fields, MISB0601_FIELD_PRECISION_TIMESTAMP, &timestamp) &&
misb0601_local_set_try_get_uint8(&fields, MISB0601_FIELD_VERSION, &version))
printf("%" PRIu64 " %u\n", timestamp, (unsigned)version);
misb0601_local_set_free(&fields);
}
}
Misb0601TagValueResultFree(&tags);
}

Browser and Node.js​

When you already have the packet bytes and an open web decoder from the web quickstart, read the version from the parsed object. Store the string containing the timestamp before crossing a JavaScript Number boundary:

const exact = decoder.requestJSON(packet);
const {status, value} = JSON.parse(exact);
if (status === 'ok') {
console.log(value.Version); // 19
console.log(exact); // contains the full integer 9007199254740993
}

Next, encode a packet and inspect its validation report with the native SDK. For JavaScript, keep the exact JSON envelope when exchanging the timestamp. See revisions, JSON, and partial results.