Data Packing
When values move between worlds — out of one module into a buffer, into a transport, out the other side back into individual values — they have to be packed at one end and unpacked at the other. NodeBlue ships a small but versatile set of modules for exactly this.
Serializer / UnSerializer — values ↔ buffer
The simplest pair: take several typed values and concatenate them into a single buffer; on the other end, split the buffer back out into the original values.
| Module | What it does |
|---|---|
| nSerializer | N typed inputs → 1 buffer output. Each input's bytes are appended to the buffer in order. |
| nUnSerializer | 1 buffer input → N typed outputs. The buffer is split back along the same boundaries. |
Both expose the type of each port (so a single Serializer can mix a u16, an f32 and three u8s into one buffer). Both have a Sync parameter (typically InputSync) and a configurable number of ports.
Typical use:
- Several sensors → one wireless packet. Six axis values → Serializer → NRF24 input. Receiver: NRF24 output → UnSerializer → six original values.
- Send a struct over UDP / MQTT. Same pattern with UDP / MQTT modules in place of NRF24.
Bit-level packing — BitPacker / BitUnPacker
When you don't have whole bytes to spare — a status byte where 8 booleans share one u8, a 12-bit reading squeezed alongside a 4-bit field, sixteen buttons crammed into two bytes — the bit-packing modules are the cleanest answer.
| Module | What it does |
|---|---|
| nBitPacker | N inputs → one packed byte array of ⌈total bits / 8⌉ bytes. Each input is mapped to a configurable bit range; once the total exceeds 8 bits, the array simply grows by another byte. The output is always a byte array, so it slots into a Serializer / Multiplexer / radio transport without further conversion. |
| nBitUnPacker | The reverse: one packed value → N outputs, each pulled from a configured bit range. |
Each port has a bit offset and bit width; the module shifts and masks for you, sign-extending where the field is signed.
Buffer Split / Merge / Not / Permute
A second group operates on whole buffers rather than individual fields.
| Module | What it does |
|---|---|
| nBufferSplit | Cut one buffer into N pieces at configured byte offsets. Each piece appears on its own output. |
| nBufferSplitCustom | Same idea but the split points are dynamic, driven from a control input. Use it for variable-length frames. |
| nBufferMerge | The reverse — concatenate N buffer inputs into a single output buffer. |
| nBufferNot | Bitwise-invert every byte in a buffer. Useful for active-low protocols, simple obfuscation, or driving certain LED strips that want the inverted bit pattern. |
| nBufferPermute | Re-order bytes in a buffer per a configured permutation table — handy for endianness fixups on multi-byte fields inside a buffer, or for un-scrambling vendor-quirk byte orders. |
Endian and Gray code utilities
Two specialised conversion modules:
| Module | What it does |
|---|---|
| nEndian | Byte-swap an integer (big↔little endian). Common when reading a sensor whose datasheet defined the registers big-endian on a little-endian MCU. |
| nGrayToBin | Convert a Gray-coded value (often produced by absolute encoders) to a normal binary integer. The inverse direction is also supported via the module's mode. |
TypeCast and Constant
Two tiny tools that pair nicely with the rest:
- nTypeCast — explicit numeric-type conversion (
f32→s16,u32→u8with saturation, etc.). Most of the time NodeBlue's wire-colour matching makes this automatic; reach forTypeCastwhen you need precise control over rounding, signedness or saturation. - nConstant — emit a fixed value as a port. Handy as a packed field that never changes (a protocol header byte, a fixed sentinel).
A worked example: a wireless 6-axis IMU packet
A common shape:
IMU axes (6 × s16) →
nSerializer(six s16 inputs, one buffer output) →nNRF24channel input.On the receiver:
nNRF24channel output →nUnSerializer(one buffer input, six s16 outputs) → downstream consumers (Dashboard graphs, HID axes, motors).
Total wire-format: 12 bytes per packet, fits comfortably in the 31-byte NodeBlue radio payload with room left over for a sequence number or a status field via the BitPacker family.
The companion to this tutorial is the Multiplexers page — multiplexing which of several flows to forward, vs. packing the contents of a single flow.
Next: how to show your values to a human — Displays.