pub enum Body {
Empty,
Bytes(Bytes),
Text(String),
Json(Value),
Stream(StreamBody),
}Expand description
The body of a message, supporting common payload types.
Variants§
Empty
No body content.
Bytes(Bytes)
Raw bytes payload.
Text(String)
UTF-8 string payload.
Json(Value)
JSON payload.
Stream(StreamBody)
Streaming payload.
Implementations§
Source§impl Body
impl Body
Sourcepub async fn into_bytes(self, max_size: usize) -> Result<Bytes, CamelError>
pub async fn into_bytes(self, max_size: usize) -> Result<Bytes, CamelError>
Convert the body into Bytes, consuming it if it is a stream.
This is an async operation because it may need to read from an underlying stream.
A max_size limit is enforced to prevent OOM errors.
Sourcepub async fn materialize(self) -> Result<Bytes, CamelError>
pub async fn materialize(self) -> Result<Bytes, CamelError>
Sourcepub fn as_text(&self) -> Option<&str>
pub fn as_text(&self) -> Option<&str>
Try to get the body as a string, converting from bytes if needed.
Sourcepub fn try_into_text(self) -> Result<Body, CamelError>
pub fn try_into_text(self) -> Result<Body, CamelError>
Convert this body to Body::Text, consuming it.
Returns Err(TypeConversionFailed) if the conversion is not possible.
Body::Stream always fails — materialize with into_bytes() first.
Sourcepub fn try_into_json(self) -> Result<Body, CamelError>
pub fn try_into_json(self) -> Result<Body, CamelError>
Convert this body to Body::Json, consuming it.
Returns Err(TypeConversionFailed) if the conversion is not possible.
Body::Stream always fails — materialize with into_bytes() first.
Sourcepub fn try_into_bytes_body(self) -> Result<Body, CamelError>
pub fn try_into_bytes_body(self) -> Result<Body, CamelError>
Convert this body to Body::Bytes, consuming it.
Returns Err(TypeConversionFailed) if the conversion is not possible.
Body::Stream always fails — materialize with into_bytes() first.