Sparkplug B Payload Compression
Some Sparkplug libraries contain utilities and helpers for doing compression and
decompression of Sparkplug B payloads. Alternatively this compress and decompression can
be done by any code or application.
Here are the steps required to apply compression to a Sparkplug B payload before publishing
it to an MQTT Server.
- Select a compression algorithm.
While there are many compression algorithms to choose from, we currently support:
- DEFLATE (ZLIB RFC 1950)
- Create the payload and encode it using Google Protocol Buffers.
This results in a typical encoded array of bytes that would normally (no compression) be published to an MQTT Server.
- Compress the payload bytes using one of the above algorithms.
- Create a new payload to wrap the compressed bytes.
This new payload should have UUID set to "SPBV1.0_COMPRESSED" and the same timestamp and sequence number as the original compressed payload. The compressed bytes should be stored in the "body" field of this new payload. A single metric should be added to the new payload to specify the algorithm used to compress the original payload. If not "algorithm" metric is present, it will be assumed that the DEFLATE algorithm was used.
Example: Payload compression with no algorithm specified (defaults to DEFLATE)
Example: Payload compression with DEFLATE algorithm
Example: Payload compression with GZIP algorithm
- Finally, encode the new payload using Google Protocol Buffers and it is ready to be published.