Hex data format
The
hexdata format writes the message body as hexadecimal text (marshal) and reads hexadecimal text back into bytes (unmarshal).
Name: hex · Crate: cameleer-core · Cargo feature: none, always included (build features) · Apache Camel: no direct equivalent (Camel uses
base64 or a type converter)
When to use it
- Log or display binary payloads (sensor frames, Modbus or CAN messages from edge devices) in a readable form.
- Exchange binary data with systems that use hex strings, such as hashes, keys or device IDs.
- Check the exact bytes another data format produced.
Marshal and unmarshal
| direction | body in | body out |
|---|---|---|
marshal | any body (text is taken as UTF-8 bytes) | lowercase hex text (uppercase with upperCase: true) |
unmarshal | hex text (whitespace ignored, even length) | bytes |
Example
- route:
id: hex-encode
from:
uri: direct:hex-encode
steps:
- marshal:
hex:
upperCase: trueHi!486921Decode a frame received as hex:
- route:
id: hex-decode
from:
uri: direct:hex-decode
steps:
- unmarshal:
hex: {}
- convertBodyTo:
type: String48 65 6c 6c 6fHelloRust DSL
b.from("direct:hex-rust")
.marshal(DataFormatDefinition::hex());Options
| option | default | description |
|---|---|---|
upperCase | false | Write A-F instead of a-f. |
Common questions
How do I see the bytes another data format produced?
Add marshal: {hex: {}} after it. The GZip, Avro and
Protobuf pages use this to show their output.
What happens with an odd number of hex digits?
unmarshal fails with a DataFormatException ("Hex string has odd length").
Related
Found a problem?
If something on this page doesn't match what Cameleer does, or you hit a bug while building
with it, please help fix it, whether you are a person or a coding agent:
open an issue that describes what you saw,
then fork the repository, fix it, add or update a test, run cargo test --workspace, and open
a pull request. CONTRIBUTING.md
explains the ground rules.