Cameleer

Hex data format

The hex data 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

directionbody inbody out
marshalany body (text is taken as UTF-8 bytes)lowercase hex text (uppercase with upperCase: true)
unmarshalhex text (whitespace ignored, even length)bytes

Example

yaml example: hex-encode
- route:
    id: hex-encode
    from:
      uri: direct:hex-encode
      steps:
        - marshal:
            hex:
              upperCase: true
text
Hi!
text
486921

Decode a frame received as hex:

yaml example: hex-decode
- route:
    id: hex-decode
    from:
      uri: direct:hex-decode
      steps:
        - unmarshal:
            hex: {}
        - convertBodyTo:
            type: String
text
48 65 6c 6c 6f
text
Hello

Rust DSL

rust
b.from("direct:hex-rust")
    .marshal(DataFormatDefinition::hex());

Options

optiondefaultdescription
upperCasefalseWrite 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").

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.

Edit this page on GitHub