Compress a TAKPacketV2 into a wire payload: [flags][zstd body].
Serializes the packet to protobuf, picks the dictionary from the packet's
CoT type (selectDictId), compresses as one independent zstd frame
(level 19, content-size/checksum/dictID frame fields off), and strips the
4-byte zstd magic. If the raw protobuf is no larger than the compressed
body, emits the skip-compress form [0xFF][raw protobuf] instead so the
payload never expands.
The packet to encode. Field units are wire units: speed
in cm/s, course in degrees×100, altitude in meters HAE (may be
negative), latitudeI/longitudeI in degrees×1e7, shape radii in cm.
A packet with no payload variant and an a-f-* CoT type is an implicit
PLI.
A Promise resolving to the compressed wire payload (Buffer).
The caller is responsible for keeping the result within the 237-byte LoRa MTU; this method does not enforce it. Use compressWithRemarksFallback when you need MTU enforcement. Asynchronous because the protobuf schema is loaded lazily.
Compress a packet, stripping remarks if the result exceeds maxWireBytes.
First attempts compression with remarks intact. If the wire payload fits within maxWireBytes, returns it as-is. Otherwise, clears the remarks field and re-compresses. Returns null if even the stripped packet exceeds the limit (caller should drop the packet).
This is a thin wrapper over compressWithRemarksFallbackDetailed
that discards the remarksStripped flag. Use the Detailed variant if you
need to tell "fit as-is", "fit after strip", and "dropped" apart — e.g.
for observability or metrics.
The packet with remarks populated.
Maximum allowed wire payload size (e.g. 225).
The wire payload, or null if the packet is too large even without remarks.
Compress a packet, stripping remarks if needed, and return a detailed result that distinguishes the four possible outcomes (see RemarksFallbackResult). Callers that want to log/meter "how often does remarks-stripping save a packet" should use this variant; compressWithRemarksFallback loses the distinction.
Compress a packet and report its sizes and emitted mode.
Equivalent to compress plus a CompressionResult describing
the protobuf size, final wire size, and the dictionary/mode actually
emitted (read back from the flags byte, so it reflects a skip-compress
0xFF fallback). Used by the golden compression-report tooling.
The packet to encode (see compress for units).
A Promise resolving to the compression statistics, including the wire payload itself.
The same conditions as compress.
Decompress a wire payload back into a TAKPacketV2.
Reads the flags byte: 0xFF means the body is raw protobuf; otherwise the
low 6 bits select the dictionary, the stripped 4-byte zstd magic is
re-prepended, and the body is decompressed with that dictionary. The
decompressed size is capped at 4096 bytes as a decompression-bomb guard
before the protobuf is parsed.
A received [flags][body] payload (must be ≥ 2 bytes).
A Promise resolving to the decoded packet. Field units are wire units (see compress).
Reserved flag bits are ignored (the dictionary ID is masked with & 0x3F).
Asynchronous because the protobuf schema is loaded lazily.
Encodes a TAKPacketV2 into the on-wire
[flags][zstd body]payload and decodes it back, using the bundled zstd dictionaries.Remarks
Wire format. A compressed payload is one flags byte (bits 0–5 = dictionary ID, bits 6–7 reserved/zero) followed by a zstd frame body whose 4-byte magic number has been stripped (re-prepended on decode). When compression would not shrink the packet, compress instead emits the flags byte
0xFFfollowed by the raw protobuf (skip-compress), so tiny payloads never expand. The total wire payload must stay within the 237-byte LoRa MTU; use compressWithRemarksFallback to enforce that with graceful remarks stripping.Resilience. Each packet is compressed as one independent, one-shot zstd frame against the static shipped dictionary — never the streaming API and never any cross-packet/adaptive state — so any single packet decodes on its own from its own bytes plus the dictionary. This is the hard resilience invariant for a lossy LoRa link.
windowLog. zstd-napi does not auto-size its compression window to a large loaded dictionary, so this class sets
windowLog: 21beforeloadDictionary(andwindowLogMax: 27on the decompressors) so small inputs can still reference deep matches in the 512 KB dictionary and peer frames with larger windows still decode. SettingwindowLogafter the dictionary is loaded would silently reset the digested dictionary.Dictionaries are loaded and digested lazily on the first
compress/decompresscall, then reused for the lifetime of the instance, so reuse oneTakCompressorrather than constructing one per packet.Example