pub struct DoipMessageBuilder { /* private fields */ }Expand description
A builder for constructing DoipMessage instances with specified headers and payloads.
This struct provides a fluent interface to configure the protocol version, payload, and automatically populate corresponding header fields based on the payload.
Implementations§
Source§impl DoipMessageBuilder
impl DoipMessageBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new DoipMessageBuilder instance using the default header and payload.
§Example
use doip_definitions::builder::DoipMessageBuilder;
let builder = DoipMessageBuilder::new();Sourcepub fn protocol_version(
self,
protocol_version: impl Into<ProtocolVersion>,
) -> Self
pub fn protocol_version( self, protocol_version: impl Into<ProtocolVersion>, ) -> Self
Sets the protocol version in the header and updates the inverse protocol version accordingly.
§Arguments
protocol_version- An object that can be converted into aProtocolVersion.
§Returns
The updated builder instance for chaining.
§Example
use doip_definitions::builder::DoipMessageBuilder;
use doip_definitions::header::ProtocolVersion;
let builder = DoipMessageBuilder::new().protocol_version(ProtocolVersion::Iso13400_2012);Sourcepub fn payload(self, payload: impl Into<DoipPayload>) -> Self
pub fn payload(self, payload: impl Into<DoipPayload>) -> Self
Sets the payload of the message and updates the header’s payload type and length accordingly.
§Arguments
payload- An object that can be converted into aDoipPayload.
§Returns
The updated builder instance for chaining.
§Panics
This method panics if the size of the provided payload cannot be determined using
core::mem::size_of_val—which may occur if dynamically sized types or trait objects
are passed in as payload components.
§Example
use doip_definitions::builder::DoipMessageBuilder;
use doip_definitions::header::PayloadType;
use doip_definitions::payload::AliveCheckRequest;
use doip_definitions::payload::DoipPayload;
let builder = DoipMessageBuilder::new().payload(DoipPayload::AliveCheckRequest(AliveCheckRequest {}));Sourcepub fn build(self) -> DoipMessage
pub fn build(self) -> DoipMessage
Finalizes the builder and returns the constructed DoipMessage.
§Returns
The fully constructed DoipMessage.
§Example
use doip_definitions::builder::DoipMessageBuilder;
use doip_definitions::header::PayloadType;
use doip_definitions::payload::AliveCheckRequest;
use doip_definitions::payload::DoipPayload;
let message = DoipMessageBuilder::new()
.payload(DoipPayload::AliveCheckRequest(AliveCheckRequest {}))
.build();