IoT Fundamentals · Study deck

Binary Data Formats for IoT

Picture a compact sensor record whose receiver swaps the byte order and reports the wrong temperature.

Physics Phoebe is your guide for this deck.

dataformatsbinary
Physics Phoebe, the module guide, in a scene from this chapter.
iotclass.org

After studying this chapter

Learning objectives

You will be able to:

  • Explain: The important idea is not "always make messages smaller." The important idea is a trade: binary formats save bytes only when both the sender and the receiver share the rules for decoding them.
  • Explain: CBOR and MessagePack: Self-Describing Binary CBOR (Concise Binary Object Representation, IETF RFC 8949) is "binary JSON": the same data model of maps, arrays, numbers, strings, and booleans, encoded as typed bytes.
  • Explain: It supports the chapter's selection rule: choose the most inspectable representation that meets the link budget and ensure every compact byte remains decodable across versions.
iotclass.org

Major section

In 60 Seconds

JavaScript Object Notation, or JSON, is a text format built from named values.

  • A protocol means shared rules for exchanging messages.
  • A binary format must define equally clear field boundaries and meaning.
  • Encode one known record, change its version, truncate it, corrupt one byte, and decode it with another implementation.

Why it matters

Saving bytes was not useful because the meaning was no longer shared.

iotclass.org

Major section

In 60 Seconds (continued)

Saving bytes was not useful because the meaning was no longer shared.

  • This runway does not prove that one format fits every link.
  • The deeper sections compare compact formats, schemas, framing, byte order, checks, versioning, tooling, and ownership costs.
  • Binary formats help when bytes, power, or storage are constrained, but the format is a contract.
iotclass.org

Major section

Start With the Story · How to Use: How It Works: Pick the Encoding Contract

You will compare compact encodings and choose a format whose decoder and version rules your system can support.

  • The first panel establishes that boundaries and an integrity check are prerequisites, while the second exposes the risk of optimizing size before defining meaning.
iotclass.org

Major section

What Compact Binary Buys

A binary data format keeps the same facts but stores them as typed bytes instead of text, so the message gets much smaller.

  • The important idea is not "always make messages smaller." The important idea is a trade: binary formats save bytes only when both the sender and the receiver share the rules for decoding them.

Why it matters

A text format such as JSON is easy to read because it spells everything out: the field names, the punctuation, and every number written as digits.

For a small temperature, humidity, and status reading, JSON spends bytes on readable field names, CBOR keeps structure with less overhead, and raw binary fits the most samples into a constrained uplink.
For a small temperature, humidity, and status reading, JSON spends bytes on readable field names, CBOR keeps structure with less overhead, and raw binary fits the most samples into a constrained uplink.
iotclass.org

Major section

What Compact Binary Buys (continued)

They pay off when bandwidth, power, or storage are tight and both ends agree on a schema or decoding contract.

  • When the link is comfortable and humans need to inspect data, readable text is often the better default.
  • Full sentences are clear to anyone but slow and bulky.
  • The capacity gain is therefore not a free ranking.
iotclass.org

Major section

What Compact Binary Buys (continued)

Shorthand is far more compact, but only readers who know your shorthand can recover the meaning.

  • For example, a battery soil-moisture node on LoRaWAN may send temperature, relative humidity, battery voltage, and a timestamp every half hour.
  • Exact byte counts change with field names, numeric ranges, and identifiers.
  • Smaller is not automatically better.
iotclass.org

Major section

What Compact Binary Buys (continued)

CBOR retains typed structure at about 18 bytes, fitting two.

  • CBOR can keep the message self-describing while shrinking the encoding, while a custom layout might store temperature as signed centidegrees and battery voltage as millivolts.
  • That last step is only sensible if the gateway, decoder tests, and version notes are owned by the same deployment.
  • The One-Minute ViewText is readable but heavy JSON carries field names, quotes, and digits as text on every message.
iotclass.org

Major section

What Compact Binary Buys (continued)

The stable pattern is what matters: JSON repeats readable structure, CBOR keeps typed structure with less text overhead, and raw binary removes nearly everything except the values and the decoder contract.

  • JSON keeps field names and punctuation visible at roughly 32 bytes, so 51 B/32 B=1.5951\ \text{B}/32\ \text{B}=1.5951 B/32 B=1.59 and only one complete reading fits.
  • Raw binary uses about 4 bytes, fitting twelve, but moves field order, scaling, byte order, status meaning, and schema version into an external contract.
  • A LoRaWAN or Sigfox node with a tiny per-message budget benefits from a compact format, because every byte is airtime and energy.
iotclass.org

Major section

What Compact Binary Buys (continued)

It supports the chapter's selection rule: choose the most inspectable representation that meets the link budget and ensure every compact byte remains decodable across versions.

  • Binary is compact but needs a contractTyped bytes drop most of the textual overhead, but the receiver must know the types, field meaning, and byte order.
  • Beginner ExamplesA device on Wi-Fi or Ethernet sending to a dashboard can keep JSON, because bandwidth and battery are not the binding constraint.
  • An opaque eight-byte payload that no current tool can decode is a liability, not an optimization.
iotclass.org

Major section

Apply It: Choose and Apply a Binary Format

CBOR and MessagePack: Self-Describing BinaryCBOR (Concise Binary Object Representation, IETF RFC 8949) is "binary JSON": the same data model of maps, arrays, numbers, strings, and booleans, encoded as typed bytes.

  • CBOR has a registered CoAP Content-Format and is a strong default for LoRaWAN and NB-IoT.

Why it matters

The first job is to place your payload on the spectrum from self-describing to schema-dependent, because that choice decides how much coordination each end needs.

A selection guide: start from the link budget, then narrow by schema flexibility and runtime constraints before reaching for custom binary.
A selection guide: start from the link budget, then narrow by schema flexibility and runtime constraints before reaching for custom binary.
iotclass.org

Major section

Apply It: Choose and Apply a Binary Format (continued)

Custom Binary: Hand-Packed BytesCustom binary defines a fixed byte layout that your code packs and unpacks directly.

  • Protocol Buffers: Schema-Defined BinaryProtocol Buffers (Protobuf) is defined by a.proto schema.
  • Each field is identified by a small field number instead of a name, so field names never travel on the wire.
  • Each branch asks what the receiver needs, making parser ownership part of the format decision.
iotclass.org

Major section

Apply It: Choose and Apply a Binary Format (continued)

That makes it very compact and very fast to parse with generated code, but it is not self-describing: both ends need the schema to decode a message.

  • It produces the smallest messages and the fastest parsing, but there is no tooling, no self-description, and no automatic schema evolution.
  • Custom binary appears last because owning its byte layout also means owning documentation, tests, and migration.
  • The sizes below are approximate and specific to this payload, but the ranking holds in general.
iotclass.org

Major section

Under the Hood: How the Bytes Are Built · Checkpoint: Summary

Each format reaches its size by removing a different layer of overhead.

  • Understanding the encoding lets you estimate payload sizes, debug wire-format problems, and evolve a schema without breaking deployed devices.
  • This map is 55 bytes.
  • Protocol Buffers EncodingA Protobuf message is a series of fields.
iotclass.org

Deck summary

Key takeaways

JavaScript Object Notation, or JSON, is a text format built from named values.

  • Saving bytes was not useful because the meaning was no longer shared.
  • You will compare compact encodings and choose a format whose decoder and version rules your system can support.
  • A binary data format keeps the same facts but stores them as typed bytes instead of text, so the message gets much smaller.
  • They pay off when bandwidth, power, or storage are tight and both ends agree on a schema or decoding contract.
iotclass.org

Retrieval practice

Recall check 1 of 4

Physics Phoebe says: answer from memory, then check your reasoning.

Q1Which format comparison gives a team the right decoder trade-off?

ATreat JSON as a fixed compact layout and CBOR as custom-schema dependent.
BJSON reads well, CBOR is compact, Protobuf needs schema and custom binary needs a parser.
CDecode Protobuf without schema and custom binary without a parser contract.
DGive the four formats identical size, schema and decoder rules.
Show answer

Answer: B Each choice trades wire size against readability, schema, and parser responsibility.

iotclass.org

Retrieval practice

Recall check 2 of 4

Physics Phoebe says: answer from memory, then check your reasoning.

Q2When is a compact binary payload format usually the right direction?

AWhen operators frequently edit raw messages and the network budget is already comfortable
BWhen the team lacks decoder tests, schema ownership, and a documented rollout plan
CWhen link, power, or storage limits matter and both ends share decoding rules
DWhen every downstream tool must inspect payloads without protocol-specific parsing or shared schemas
Show answer

Answer: C Binary formats save bytes only when the decoding rules are explicit and shared by both ends.

iotclass.org

Retrieval practice

Recall check 3 of 4

Physics Phoebe says: answer from memory, then check your reasoning.

Q3A LoRaWAN sensor must send temperature, humidity, and a timestamp every 15 minutes, and the payload limit at its data rate is about 51 bytes. The team wants minimal deployment coordination. Which format fits best?

AJSON, because readable field names matter more than fitting the radio frame
BProtocol Buffers, because generated types keep encoders and decoders consistent across the fleet
CCustom binary, because fixed offsets leave more of the radio frame available for future fields
DCBOR, because the fields fit the limit while decoding stays schema-free for deployment
Show answer

Answer: D CBOR comfortably fits this payload and needs no shared schema, which keeps a simple deployment simple.

iotclass.org

Retrieval practice

Recall check 4 of 4

Physics Phoebe says: answer from memory, then check your reasoning.

Q4A team must add a new optional field to a deployed Protobuf message without breaking devices still running the old firmware. What is the safe change?

AReuse a retired number and document the meaning change in release notes
BRename an existing field while keeping its number and wire type unchanged
CAdd a new field number so old readers skip the unknown field
DChange the whole wire encoding and update devices during normal operation later
Show answer

Answer: C Unknown field numbers are skipped by older decoders, so new and old code interoperate.

iotclass.org

Print reference

Answers

Answer key.

  1. B · Each choice trades wire size against readability, schema, and parser responsibility.
  2. C · Binary formats save bytes only when the decoding rules are explicit and shared by both ends.
  3. D · CBOR comfortably fits this payload and needs no shared schema, which keeps a simple deployment simple.
  4. C · Unknown field numbers are skipped by older decoders, so new and old code interoperate.
iotclass.org