Skip to main content

Protocol Translation Rules

Protocol translation involves not just mapping headers and metadata between different messaging protocols, but also transforming the payload data itself. This document outlines the standardized rules we use for converting between different data formats while preserving semantic meaning.

Payload Transformation Basics

When messages travel between different protocols, the payload often needs to be transformed to accommodate:

  1. Different data formats (JSON, XML, CBOR, Protocol Buffers, etc.)
  2. Different data models (hierarchical vs. flat)
  3. Different encoding schemes (UTF-8, ASCII, binary)
  4. Different size constraints (some protocols have stricter payload size limits)

Our translation engine applies the following principles to ensure reliable message conversions:

Principle: Preserve semantic equivalence over syntactic exactness

Data Format Transformations

Below are examples of how our system transforms data between common formats:

JSON to XML Transformation

{
"sensor": {
"id": "temp_01",
"reading": 22.5,
"unit": "celsius",
"timestamp": 1633372800
}
}

Transforms to:

<sensor>
<id>temp_01</id>
<reading>22.5</reading>
<unit>celsius</unit>
<timestamp>1633372800</timestamp>
</sensor>

JSON to CBOR Transformation

JSON data is converted to CBOR's efficient binary format while preserving structure:

{
"command": "activate",
"device": "lighting",
"zone": "kitchen",
"level": 80
}

Transforms to CBOR (shown in hex):

A4                                      # map(4)
67 # text(7)
636F6D6D616E64 # "command"
68 # text(8)
61637469766174 # "activate"
66 # text(6)
646576696365 # "device"
68 # text(8)
6C69676874696E67 # "lighting"
64 # text(4)
7A6F6E65 # "zone"
67 # text(7)
6B69746368656E # "kitchen"
65 # text(5)
6C6576656C # "level"
18 50 # unsigned(80)

Protocol Buffer Serialization

For IoT gateways using Protocol Buffers:

syntax = "proto3";

message SensorReading {
string device_id = 1;
double value = 2;
string unit = 3;
int64 timestamp = 4;
}

Our translation engine handles serialization and deserialization to other formats automatically.

Common Transformation Rules

Source FormatTarget FormatTransformation RuleSpecial Considerations
JSONXMLObject properties become elements; arrays become repeated elementsJSON null values transformed to empty XML elements with xsi:nil="true"
XMLJSONElements become properties; attributes become properties with @ prefixNamespace information may be lost
JSONCBORDirect structural mapping with binary encodingResults in smaller payload size
MQTT (Binary)CoAPContent-Format header added to specify payload typeMay need chunking for large payloads
Plain TextJSONText stored in {"value": "text content"} objectEscaping special characters
AMQP (AMQP Value)MQTTType information mapped to MQTT properties in 5.0Type information lost in MQTT 3.1.1

Data Type Mappings

The following type mappings are preserved during protocol translations:

Data TypeJSONXMLCBORProtocol Buffers
Integernumberintegerintegerint32/int64
Floatnumberdecimalfloatfloat/double
Stringstringstringtextstring
Booleantrue/falsetrue/falsetrue/falsebool
Array[]repeated elementsarrayrepeated
Objectnested elementsmapmessage
Binarybase64 stringbase64 stringbytesbytes
Nullnullxsi:nil="true"nulldefault values

Content Negotiation Process

When a client connects through one protocol (e.g., MQTT) and subscribers expect another format (e.g., AMQP), our broker:

  1. Identifies the original content type
  2. Converts payload according to transformation rules
  3. Adds appropriate content type headers
  4. Delivers the transformed message

Best Practices for Protocol Integration

When designing systems that will use cross-protocol messaging:

  1. Define a canonical data model for your domain that maps well to multiple formats
  2. Include content type metadata whenever possible
  3. Use schema validation on both ends to ensure transformation integrity
  4. Test with edge cases including empty values, special characters, and very large payloads
  5. Document format expectations for each integration point

Advanced Features Enterprise

Enterprise users can create custom transformation rules for proprietary formats and configure validation pipelines to ensure data integrity during translation.

// Example custom transformation configuration
{
"sourceFormat": "CSV",
"targetFormat": "JSON",
"fieldMap": [
{"source": "column1", "target": "deviceId"},
{"source": "column2", "target": "readings.temperature"},
{"source": "column3", "target": "readings.humidity"}
],
"transforms": [
{"field": "readings.temperature", "function": "multiply", "value": 9/5},
{"field": "readings.temperature", "function": "add", "value": 32}
]
}

Performance Considerations

Translation operations have performance implications:

  • JSON ↔ XML transformations are more CPU intensive
  • Binary formats like CBOR and Protocol Buffers offer better performance
  • Pre-compiled schemas can accelerate Protocol Buffer translations
  • Caching frequently used transformations improves throughput

By following these translation rules, messages can flow seamlessly across protocol boundaries while maintaining their semantic meaning.