Skip to content

Message Format

The message_format defines the structure of messages exchanged between nodes through topics, services, and actions. It is a map of field names to schema types. A native interface entry declares it inline in peppy.json5; an entry that carries a link_id into a contract or pairing document takes its shape from that document instead, using the same syntax there, and an inline message_format on such an entry is rejected at parse time. Such an entry may pin the length of arrays the document leaves generic through a refine block; see Refining the contract’s generic arrays.

message_format: {
temperature: "f32",
label: "string",
}

Each field value is a schema type: either a bare type token, or a structured schema with modifiers.


A bare type string is the simplest form. These map directly to language-native types.

TypeRust typePython type
"bool"boolbool
"u8"u8int
"u16"u16int
"u32"u32int
"u64"u64int
"i8"i8int
"i16"i16int
"i32"i32int
"i64"i64int
"f32"f32float
"f64"f64float
"string"Stringstr
"bytes"Vec<u8>bytes
"time"std::time::SystemTimefloat

One field name is reserved: instance_id is rejected anywhere in a message_format, at the root or nested, because peppy’s transport metadata claims it.


A field with a presence bit on the wire can be made optional by using the structured form with $optional:

note: {
$type: "string",
$optional: true
}
FieldRequiredDescription
$typeYesstring, bytes, or time (arrays and objects take $optional in their own structured forms)
$optionalNoWhen true, the field may be absent. Defaults to false

Scalar-copy types (bool, the integer types, f32, f64) carry no presence bit, so an absent value is indistinguishable from a zero one: $optional on them is rejected when the config is parsed. Leave out $optional, or hold the value in an optional object, which is absent as a whole:

max_speed: { $type: "object", $optional: true, value: "f64" }

$optional applies at any depth: to a field of the message_format, to a field of a nested object, and to a field of the objects an array holds. Each object holds the presence of its own fields, so each item of this array gives its orientation or leaves it out:

waypoints: {
$type: "array",
$items: {
$type: "object",
position: { $type: "array", $items: "f64", $length: 3 },
orientation: { $type: "array", $items: "f64", $length: 4, $optional: true }
}
}

The field is an Option<T> in the Rust struct of its object and an Optional[T] in its Python dataclass. The items of an array take no $optional: each item of an array is present, and an optional array is absent as a whole.


Use $enum on a string field to document the closed set of allowed string values:

mode: {
$type: "string",
$enum: ["idle", "moving", "holding"]
}
FieldRequiredDescription
$typeYesMust be "string". Rejected on any other type.
$enumYesNon-empty list of unique, non-empty strings, preserved in declared order.
$optionalNoSame as on any string field.

$enum is metadata only: it does not change the wire encoding or generated Rust/Python types (the field remains a plain string), and Peppy does not enforce it at runtime. Tools and external validators read the allowed values through the codec API.


Use $marks in a field’s structured form to attach semantic tags (such as identifying an item ID or pose) for external tools and clients:

target: {
$type: "object",
item: { $type: "string", $marks: ["item_id"] },
pose: { $type: "array", $items: "f64", $length: 7, $marks: ["pose"] }
}
FieldRequiredDescription
$marksNoNon-empty list of unique mark names. Omit when the field has no marks. Supported on primitives, arrays, and objects in structured form.

Mark names must be 1 to 64 characters in snake_case (lowercase ASCII letters and digits, each word starting with a letter, separated by single _, such as item_id or pose2d).

$marks is metadata only: it does not change the wire format or generated code, and Peppy does not act on field marks. Clients define and inspect them through the codec API. Contract members can also carry member marks.


Use $description in a field’s structured form to explain what the field holds. Primitives, arrays, and objects all accept it.

  • On an array, place $description beside $items. Array items themselves do not take $description (use the array’s $description for the collection, and per-field $description inside object items).
  • On an object, place $description beside the field keys.
message_format: {
speed: { $type: "f64", $description: "The speed of the base, in meters per second." },
target: {
$type: "object",
$description: "The point to go to, in the frame of the map.",
x: "f64",
y: "f64"
},
path: {
$type: "array",
$description: "The points on the way to the target, in order.",
$items: { $type: "object", x: "f64", y: "f64" }
}
}
FieldRequiredDescription
$descriptionNoNon-blank string describing the field. Omit if unused.

$description does not change the wire format or generated code, and Peppy reads no rules from it. It is surfaced by the codec API, peppy node describe, and the MCP server (as JSON Schema property description). Document-level and member-level descriptions are required; see Descriptions.


An object groups related fields into a nested structure. It generates a nested struct in Rust and a dataclass in Python.

header: {
frame: "string",
timestamp: "time",
capture_index: "u32"
}
FieldRequiredDescription
$typeNoOnly valid value is "object". Can be omitted since the parser infers it from the structure
$optionalNoWhen true, the entire object may be absent
other keysNoEach additional key is a field with its own schema type

Object fields can be any schema type, including arrays and nested objects:

sensor_reading: {
$type: "object",
header: {
$type: "object",
frame: "string",
timestamp: "time",
capture_index: "u32"
},
samples: {
$type: "array",
$items: "f32"
}
}

An array represents a list of items of the same type.

distances: {
$type: "array",
$items: "f32"
}
FieldRequiredDescription
$typeYesMust be "array"
$itemsYesA primitive type or an object schema. Nested arrays (arrays of arrays) are not supported, and the items take no $description: the array has it
$lengthNoFixed number of elements. Only supported when $items is a numeric or boolean primitive (not supported for string, bytes, time, or object items). Omit for variable-length; a node implementing or consuming the document may then pin it through its entry’s refine block
$optionalNoWhen true, the entire array may be absent

When $length is provided, the array has an exact number of elements:

position: {
$type: "array",
$items: "f32",
$length: 3
}

This maps to [f32; 3] in Rust and list[float] in Python, where the generated code raises a ValueError when a list of any other length is encoded or decoded.

Without $length, the array can contain any number of elements:

frame: {
$type: "array",
$items: "u8"
}

This maps to Vec<u8> in Rust and bytes in Python (for u8 items) or list[T] for other types.

$items can be an object, allowing arrays of structured records:

transforms: {
$type: "array",
$items: {
$type: "object",
frame: "string",
child_frame: "string",
position: {
$type: "array",
$items: "f64",
$length: 3
},
orientation: {
$type: "array",
$items: "f64",
$length: 4
}
}
}

This accepts messages like:

{
"transforms": [
{ "frame": "base_link", "child_frame": "link1", "position": [0.0, 0.0, 1.0], "orientation": [0.0, 0.0, 0.0, 1.0] },
{ "frame": "link1", "child_frame": "link2", "position": [0.0, 1.0, 0.0], "orientation": [0.0, 0.0, 0.0, 1.0] }
]
}

Schema types can be nested arbitrarily:

  • Object fields can be primitives, arrays, or other objects
  • Array items can be primitives or objects (nested arrays are not supported)

This enables complex hierarchical message structures. For example, a robotics transform tree:

message_format: {
timestamp: "time",
transforms: {
$type: "array",
$items: {
$type: "object",
frame: "string",
child_frame: "string",
position: { $type: "array", $items: "f64", $length: 3 },
orientation: { $type: "array", $items: "f64", $length: 4 }
}
}
}

A full peppy.json5 topic using multiple schema types:

{
peppy_schema: "node/v1",
manifest: {
name: "arm_controller",
tag: "v1",
description: ["The controller of a six-joint arm with a gripper: it publishes the state of the arm."]
},
execution: {
language: "rust",
run_cmd: ["./target/release/arm_controller"],
},
interfaces: {
topics: {
emits: [
{
name: "arm_state",
description: "The joints and the end effector of the arm, at each control step.",
qos_profile: "sensor_data",
message_format: {
timestamp: { $type: "time", $description: "The time of the measure." },
joint_positions: { $type: "array", $items: "f64", $length: 6 },
joint_velocities: { $type: "array", $items: "f64", $length: 6 },
end_effector: {
$type: "object",
position: { $type: "array", $items: "f64", $length: 3 },
orientation: { $type: "array", $items: "f64", $length: 4 },
gripper_open: "bool"
}
}
}
]
}
}
}