Content
Each message names the media type of the codec that reads or writes it; the root defaultContentType appears only when all of them agree.
The media type is the codec's CONTENT_TYPE: application/json, application/cbor or application/msgpack.
It follows the codec chosen for the mounting, at whichever level chose it.
A message that no codec reads or writes names none: a type that carries its own bytes, on a byte lane.
A reader applies the root defaultContentType to each message that names no media type.
So it stands only while every message names the same one; a second format, or a message without one, leaves it out.
A message shared by several registrations takes the media type of the first.
Example
The example needs the cbor feature:
cargo test --example asyncapi_content_type --features macros,memory,asyncapi,cbor
- Macros
- Manual
fn app() -> impl App {
RustStream::new(AppInfo::new("plant", "0.1.0"))
// The default codec: `Order` is `application/json`.
.with_broker(MemoryBroker::new(), |b| {
b.include(accept);
})
// The scope's codec: `Reading` is `application/cbor`.
.with_broker_codec(MemoryBroker::new(), CborCodec, |b| {
b.include(record);
})
}
fn app() -> impl App {
RustStream::new(AppInfo::new("plant", "0.1.0"))
// The default codec: `Order` is `application/json`.
.with_broker(MemoryBroker::new(), |b| {
b.include(subscriber("orders", Accept).build());
})
// The scope's codec: `Reading` is `application/cbor`.
.with_broker_codec(MemoryBroker::new(), CborCodec, |b| {
b.include(subscriber("readings", Record).build());
})
}