VLink  2.3.0
A high-performance communication middleware
vlink::SomeipSerializer::Writer Class Referencefinal

Bounds-checked SOME/IP payload writer. More...

#include <someip_serializer.h>

Collaboration diagram for vlink::SomeipSerializer::Writer:

Public Member Functions

 Writer (uint8_t *data, size_t capacity, size_t alignment=1U, Endian endian=Endian::kBig) noexcept
 Creates a writer over data with capacity bytes. More...
 
size_t position () const noexcept
 Returns the number of bytes consumed by this writer. More...
 
bool is_size_only () const noexcept
 Reports whether this writer only measures encoded size. More...
 
Writer size_only () const noexcept
 Creates a size-only cursor at the current position. More...
 
bool append (const uint8_t *data, size_t size) noexcept
 Appends size bytes without alignment padding. More...
 
bool append_unsigned (uint64_t value, size_t width) noexcept
 Appends the low width bytes of value in the configured byte order. More...
 
bool append_unsigned (uint64_t value, size_t width, Endian endian) noexcept
 Appends the low width bytes of value in an explicit byte order. More...
 
bool begin_length_delimited (size_t &length_position, size_t &data_position, size_t width=sizeof(uint32_t)) noexcept
 Reserves a length field and records its payload start. More...
 
bool end_length_delimited (size_t length_position, size_t data_position, size_t width=sizeof(uint32_t)) noexcept
 Finalizes a reserved length field from the current position. More...
 
bool align () noexcept
 Pads the current position to the configured AUTOSAR alignment. More...
 

Detailed Description

Bounds-checked SOME/IP payload writer.

A null destination performs a size-only pass. A non-null destination never grows or replaces storage, which allows exact transport loans to be written in place. Every successful append advances position() by the encoded byte count; a failed append leaves the cursor unchanged. The writer never advances beyond kMaxPayloadSize.

Constructor & Destructor Documentation

◆ Writer()

vlink::SomeipSerializer::Writer::Writer ( uint8_t *  data,
size_t  capacity,
size_t  alignment = 1U,
Endian  endian = Endian::kBig 
)
noexcept

Creates a writer over data with capacity bytes.

Passing nullptr selects size-only mode. Otherwise data must remain valid for capacity bytes throughout the writer lifetime. Values above kMaxPayloadSize are clamped to that wire-format limit. The writer does not own or initialize the destination storage.

Parameters
dataDestination buffer, or nullptr for size-only mode.
capacityNumber of writable bytes, or the maximum size to measure.
alignmentAUTOSAR payload alignment: 1, 2, 4, 8, 16, or 32 bytes.
endianByte order for payload scalar values.

Member Function Documentation

◆ align()

bool vlink::SomeipSerializer::Writer::align ( )
noexcept

Pads the current position to the configured AUTOSAR alignment.

Returns
true on success; false when the destination is too small.
Here is the caller graph for this function:

◆ append()

bool vlink::SomeipSerializer::Writer::append ( const uint8_t *  data,
size_t  size 
)
noexcept

Appends size bytes without alignment padding.

Size-only mode advances the cursor without reading data. In write mode, data must identify at least size readable bytes when size is not zero and must not overlap the destination range written by this operation.

Parameters
dataSource bytes.
sizeNumber of bytes to append.
Returns
true on success; false when the destination is too small.
Here is the caller graph for this function:

◆ append_unsigned() [1/2]

bool vlink::SomeipSerializer::Writer::append_unsigned ( uint64_t  value,
size_t  width 
)
noexcept

Appends the low width bytes of value in the configured byte order.

Parameters
valueUnsigned value containing the bits to encode.
widthEncoded width in bytes; must be in the range [1,8].
Returns
true on success; false for an invalid width or insufficient storage.
Here is the caller graph for this function:

◆ append_unsigned() [2/2]

bool vlink::SomeipSerializer::Writer::append_unsigned ( uint64_t  value,
size_t  width,
Endian  endian 
)
noexcept

Appends the low width bytes of value in an explicit byte order.

Wire-format metadata such as TLV tags and union type selectors keeps network byte order independently of the configured payload byte order.

Parameters
valueUnsigned value containing the bits to encode.
widthEncoded width in bytes; must be in the range [1,8].
endianByte order for this value only.
Returns
true on success; false for an invalid width or insufficient storage.

◆ begin_length_delimited()

bool vlink::SomeipSerializer::Writer::begin_length_delimited ( size_t &  length_position,
size_t &  data_position,
size_t  width = sizeof(uint32_t) 
)
noexcept

Reserves a length field and records its payload start.

Parameters
length_positionOutput offset of the reserved length field.
data_positionOutput offset of the first length-delimited byte.
widthEncoded width in bytes; must be 1, 2, or 4.
Returns
true on success; false when the field cannot be reserved.
Here is the caller graph for this function:

◆ end_length_delimited()

bool vlink::SomeipSerializer::Writer::end_length_delimited ( size_t  length_position,
size_t  data_position,
size_t  width = sizeof(uint32_t) 
)
noexcept

Finalizes a reserved length field from the current position.

Stores position()-data_position as an unsigned byte count at length_position. The current position is not changed.

Parameters
length_positionOffset returned by begin_length_delimited().
data_positionPayload start returned by begin_length_delimited().
widthEncoded width in bytes; must be 1, 2, or 4.
Returns
true on success; false on an invalid range or length overflow.
Here is the caller graph for this function:

◆ is_size_only()

bool vlink::SomeipSerializer::Writer::is_size_only ( ) const
noexcept

Reports whether this writer only measures encoded size.

Returns
true when no destination buffer is attached.
Here is the caller graph for this function:

◆ position()

size_t vlink::SomeipSerializer::Writer::position ( ) const
noexcept

Returns the number of bytes consumed by this writer.

Returns
Current zero-based write position in bytes.
Here is the caller graph for this function:

◆ size_only()

Writer vlink::SomeipSerializer::Writer::size_only ( ) const
noexcept

Creates a size-only cursor at the current position.

Returns
A writer preserving capacity, position, alignment, and byte order without a destination buffer.
Here is the caller graph for this function:

The documentation for this class was generated from the following file: