Serialization Requirements¶
This section defines Software Low-Level Requirements (SW-LLR) for the SOME/IP payload serialization and deserialization engine. All multi-byte values use Big Endian (network byte order) encoding.
Overview¶
The serialization engine handles:
Primitive types (integers, floats, booleans)
Complex types (arrays, strings, structs)
Buffer management and overflow protection
Primitive Type Serialization¶
Unsigned Integer Types¶
The software shall serialize uint8 values as a single byte without byte order conversion. Rationale: Single-byte values have no endianness concern. Code Location: |
The software shall serialize uint16 values as 2 bytes in Big Endian byte order. Rationale: SOME/IP uses Big Endian for multi-byte values. Code Location: |
The software shall serialize uint32 values as 4 bytes in Big Endian byte order. Rationale: SOME/IP uses Big Endian for multi-byte values. Code Location: |
The software shall serialize uint64 values as 8 bytes in Big Endian byte order. Rationale: SOME/IP uses Big Endian for multi-byte values. Code Location: |
The software shall deserialize uint8 values from a single byte without byte order conversion. Rationale: Single-byte values have no endianness concern. Code Location: |
The software shall deserialize uint16 values from 2 bytes in Big Endian byte order to host byte order. Rationale: SOME/IP uses Big Endian for multi-byte values. Code Location: |
The software shall deserialize uint32 values from 4 bytes in Big Endian byte order to host byte order. Rationale: SOME/IP uses Big Endian for multi-byte values. Code Location: |
The software shall deserialize uint64 values from 8 bytes in Big Endian byte order to host byte order. Rationale: SOME/IP uses Big Endian for multi-byte values. Code Location: |
Signed Integer Types¶
The software shall serialize int8 values as a single byte using two’s complement representation. Rationale: Standard signed integer representation. Code Location: |
The software shall serialize int16 values as 2 bytes in Big Endian byte order using two’s complement representation. Rationale: SOME/IP uses Big Endian and two’s complement for signed integers. Code Location: |
The software shall serialize int32 values as 4 bytes in Big Endian byte order using two’s complement representation. Rationale: SOME/IP uses Big Endian and two’s complement for signed integers. Code Location: |
The software shall serialize int64 values as 8 bytes in Big Endian byte order using two’s complement representation. Rationale: SOME/IP uses Big Endian and two’s complement for signed integers. Code Location: |
The software shall deserialize int8 values from a single byte using two’s complement interpretation. Rationale: Standard signed integer representation. Code Location: |
The software shall deserialize int16 values from 2 bytes in Big Endian byte order using two’s complement interpretation. Rationale: SOME/IP uses Big Endian and two’s complement for signed integers. Code Location: |
The software shall deserialize int32 values from 4 bytes in Big Endian byte order using two’s complement interpretation. Rationale: SOME/IP uses Big Endian and two’s complement for signed integers. Code Location: |
The software shall deserialize int64 values from 8 bytes in Big Endian byte order using two’s complement interpretation. Rationale: SOME/IP uses Big Endian and two’s complement for signed integers. Code Location: |
Primitive Type Error Handling¶
The software shall return an error when serializing a uint8 value and the buffer has less than 1 byte remaining capacity. Rationale: Prevent buffer overflow. Error Handling: Return BUFFER_OVERFLOW error code. Code Location: |
The software shall return an error when serializing a uint16 value and the buffer has less than 2 bytes remaining capacity. Rationale: Prevent buffer overflow. Error Handling: Return BUFFER_OVERFLOW error code. Code Location: |
The software shall return an error when serializing a uint32 value and the buffer has less than 4 bytes remaining capacity. Rationale: Prevent buffer overflow. Error Handling: Return BUFFER_OVERFLOW error code. Code Location: |
The software shall return an error when serializing a uint64 value and the buffer has less than 8 bytes remaining capacity. Rationale: Prevent buffer overflow. Error Handling: Return BUFFER_OVERFLOW error code. Code Location: |
The software shall return an error when deserializing a uint8 value and the buffer has less than 1 byte remaining data. Rationale: Prevent buffer overread. Error Handling: Return INSUFFICIENT_DATA error code. Code Location: |
The software shall return an error when deserializing a uint16 value and the buffer has less than 2 bytes remaining data. Rationale: Prevent buffer overread. Error Handling: Return INSUFFICIENT_DATA error code. Code Location: |
The software shall return an error when deserializing a uint32 value and the buffer has less than 4 bytes remaining data. Rationale: Prevent buffer overread. Error Handling: Return INSUFFICIENT_DATA error code. Code Location: |
The software shall return an error when deserializing a uint64 value and the buffer has less than 8 bytes remaining data. Rationale: Prevent buffer overread. Error Handling: Return INSUFFICIENT_DATA error code. Code Location: |
Boolean Type Serialization¶
The software shall serialize boolean true as the byte value 0x01. Rationale: Standard SOME/IP boolean encoding. Code Location: |
The software shall serialize boolean false as the byte value 0x00. Rationale: Standard SOME/IP boolean encoding. Code Location: |
The software shall deserialize byte value 0x00 as boolean false. Rationale: Standard SOME/IP boolean encoding. Code Location: |
The software shall deserialize byte value 0x01 as boolean true. Rationale: Standard SOME/IP boolean encoding. Code Location: |
The software shall deserialize byte values 0x02 through 0xFF as boolean true for interoperability. Rationale: Robust parsing accepting any non-zero as true. Code Location: |
The software shall return an error when serializing a boolean value and the buffer has less than 1 byte remaining capacity. Rationale: Prevent buffer overflow. Error Handling: Return BUFFER_OVERFLOW error code. Code Location: |
The software shall return an error when deserializing a boolean value and the buffer has no remaining data. Rationale: Prevent buffer overread. Error Handling: Return INSUFFICIENT_DATA error code. Code Location: |
Floating Point Serialization¶
The software shall serialize float32 values as 4 bytes in IEEE 754 single precision format with Big Endian byte order. Rationale: SOME/IP uses IEEE 754 for floating point values. Code Location: |
The software shall serialize float64 values as 8 bytes in IEEE 754 double precision format with Big Endian byte order. Rationale: SOME/IP uses IEEE 754 for floating point values. Code Location: |
The software shall deserialize float32 values from 4 bytes in IEEE 754 single precision format with Big Endian byte order. Rationale: SOME/IP uses IEEE 754 for floating point values. Code Location: |
The software shall deserialize float64 values from 8 bytes in IEEE 754 double precision format with Big Endian byte order. Rationale: SOME/IP uses IEEE 754 for floating point values. Code Location: |
The software shall preserve IEEE 754 special values (NaN, positive infinity, negative infinity) during float32 serialization and deserialization. Rationale: Special floating point values must be handled correctly. Code Location: |
The software shall preserve IEEE 754 special values (NaN, positive infinity, negative infinity) during float64 serialization and deserialization. Rationale: Special floating point values must be handled correctly. Code Location: |
The software shall return an error when serializing a float32 value and the buffer has less than 4 bytes remaining capacity. Rationale: Prevent buffer overflow. Error Handling: Return BUFFER_OVERFLOW error code. Code Location: |
The software shall return an error when serializing a float64 value and the buffer has less than 8 bytes remaining capacity. Rationale: Prevent buffer overflow. Error Handling: Return BUFFER_OVERFLOW error code. Code Location: |
The software shall return an error when deserializing a float32 value and the buffer has less than 4 bytes remaining data. Rationale: Prevent buffer overread. Error Handling: Return INSUFFICIENT_DATA error code. Code Location: |
The software shall return an error when deserializing a float64 value and the buffer has less than 8 bytes remaining data. Rationale: Prevent buffer overread. Error Handling: Return INSUFFICIENT_DATA error code. Code Location: |
Array Serialization¶
Fixed Length Arrays¶
The software shall serialize fixed-length arrays as N consecutive elements, where N is the fixed array size. Rationale: Fixed arrays have known size at compile time. Code Location: |
The software shall calculate fixed-length array size as N multiplied by the size of each element. Rationale: Array size calculation for buffer management. Code Location: |
The software shall deserialize fixed-length arrays by reading N consecutive elements. Rationale: Fixed arrays have known size at compile time. Code Location: |
Dynamic Length Arrays¶
The software shall serialize the length field of dynamic arrays as a 4-byte value in Big Endian byte order. Rationale: Dynamic arrays require a length field. Code Location: |
The software shall serialize the array length field immediately before the array element data. Rationale: Length is needed before parsing elements. Code Location: |
The software shall serialize empty dynamic arrays with a length field value of 0 and no element data. Rationale: Empty arrays are valid and common. Code Location: |
The software shall read the 4-byte length field first when deserializing a dynamic array. Rationale: Length determines how many elements to read. Code Location: |
The software shall deserialize array elements according to the count specified in the length field. Rationale: Parse the correct number of elements. Code Location: |
Array Error Handling¶
The software shall return an error when serializing an array that would exceed the remaining buffer capacity. Rationale: Prevent buffer overflow. Error Handling: Return BUFFER_OVERFLOW error code. Code Location: |
The software shall return an error when the array size would exceed the maximum value representable in the 4-byte length field. Rationale: Prevent length field overflow. Error Handling: Return ARRAY_TOO_LARGE error code. Code Location: |
The software shall return an error when deserializing a dynamic array and there are less than 4 bytes remaining for the length field. Rationale: Prevent buffer overread. Error Handling: Return INSUFFICIENT_DATA error code. Code Location: |
The software shall return an error when deserializing a dynamic array and the remaining buffer is smaller than the declared array size. Rationale: Prevent buffer overread. Error Handling: Return INSUFFICIENT_DATA error code. Code Location: |
The software shall return an error when the array length field value is not evenly divisible by the element size. Rationale: Ensures complete elements in array data. Error Handling: Return MALFORMED_DATA error code. Code Location: |
String Serialization¶
The software shall serialize strings using UTF-8 encoding. Rationale: SOME/IP specifies UTF-8 for string encoding. Code Location: |
The software shall serialize the string length field as a 4-byte value that includes the BOM (3 bytes) and null terminator (1 byte) in addition to the string content. Rationale: Length field represents total byte count. Code Location: |
The software shall prepend the UTF-8 Byte Order Mark (0xEF 0xBB 0xBF) at the start of serialized strings. Rationale: BOM indicates UTF-8 encoding. Code Location: |
The software shall append a null terminator (0x00) at the end of serialized strings. Rationale: Null termination for C-style string compatibility. Code Location: |
The software shall serialize empty strings with length field value 4 (BOM + terminator), followed by the BOM and null terminator. Rationale: Empty strings still require BOM and terminator. Code Location: |
The software shall read the 4-byte length field first when deserializing a string. Rationale: Length determines string byte count. Code Location: |
The software shall extract the string content by removing the BOM and null terminator after reading the raw bytes. Rationale: Application receives clean string data. Code Location: |
String Error Handling¶
The software shall return an error when deserializing a string that does not end with a null terminator. Rationale: Malformed string detection. Error Handling: Return MALFORMED_DATA error code. Code Location: |
The software shall detect invalid UTF-8 sequences during string deserialization and handle according to configuration (error or replace). Rationale: UTF-8 validation for data integrity. Error Handling: Return INVALID_ENCODING error or replace with replacement character. Code Location: |
The software shall return an error when serializing a string that would exceed the remaining buffer capacity. Rationale: Prevent buffer overflow. Error Handling: Return BUFFER_OVERFLOW error code. Code Location: |
The software shall return an error when deserializing a string and the remaining buffer is smaller than the declared string length. Rationale: Prevent buffer overread. Error Handling: Return INSUFFICIENT_DATA error code. Code Location: |
Struct Serialization¶
The software shall serialize struct members sequentially in their declaration order. Rationale: Deterministic serialization order. Code Location: |
The software shall not insert implicit padding bytes between struct members during serialization. Rationale: SOME/IP structs are packed by default. Code Location: |
The software shall support explicit alignment configuration, adding padding bytes only when alignment is explicitly specified. Rationale: Some use cases require aligned access. Code Location: |
The software shall deserialize struct members sequentially in their expected order. Rationale: Match serialization order. Code Location: |
Struct Error Handling¶
The software shall return an error when deserializing a struct and the buffer ends before all members have been read. Rationale: Prevent incomplete struct deserialization. Error Handling: Return INSUFFICIENT_DATA error code. Code Location: |
The software shall return an error when serializing a struct that would exceed the remaining buffer capacity. Rationale: Prevent buffer overflow. Error Handling: Return BUFFER_OVERFLOW error code. Code Location: |
Buffer Management¶
The software shall check buffer capacity before serializing any value to ensure sufficient space is available. Rationale: Prevents partial writes and buffer overflow. Code Location: |
The software shall return an appropriate error code when a serialization operation would exceed buffer capacity. Rationale: Consistent error handling for overflow conditions. Error Handling: Return BUFFER_OVERFLOW error code. Code Location: |
The software shall not modify the buffer when a serialization operation would cause an overflow. Rationale: Atomic operation semantics; buffer remains valid on error. Error Handling: Return error without modifying buffer. Code Location: |
The software shall return an error when a null buffer pointer is provided for serialization or deserialization. Rationale: Prevents null pointer dereference. Error Handling: Return INVALID_ARGUMENT error code. Code Location: |
The software shall return an error when a buffer with zero capacity is provided for serialization. Rationale: Zero-capacity buffer cannot hold any data. Error Handling: Return BUFFER_OVERFLOW error code. Code Location: |
The software shall track the current position in the buffer during sequential serialization and deserialization operations. Rationale: Enables sequential value access. Code Location: |
The software shall provide a method to query the remaining buffer capacity (total size minus current position). Rationale: Enables pre-checking before serialization. Code Location: |
The software shall provide a method to reset the buffer position to the beginning for re-reading. Rationale: Enables re-parsing of buffer contents. Code Location: |
Alignment Support¶
The software shall support aligning the buffer position to a specified boundary by adding padding bytes. Rationale: Some data types may require alignment. Code Location: |
The software shall use zero (0x00) as the value for alignment padding bytes. Rationale: Deterministic padding content. Code Location: |
The software shall skip alignment padding bytes when deserializing aligned data structures. Rationale: Padding bytes are not part of actual data. Code Location: |
Enumeration Serialization¶
The software shall serialize enumeration values based on unsigned integer datatypes (uint8, uint16, uint32, uint64) as defined by the interface specification. Rationale: Enumerations map symbolic names to integer wire values per the interface definition. Code Location: |
The software shall support sending and receiving undefined enumeration values unless configured otherwise. Rationale: Accepting undefined enum values enables forward compatibility with newer interface versions. Code Location: |
Bitfield Serialization¶
The software shall transport bitfields as basic datatypes uint8, uint16, or uint32. Rationale: Bitfields pack multiple boolean or small-range values into compact integer types. Code Location: |
The software shall support interface-specified names for each bit and the values each bit can take within a bitfield. Rationale: Named bits make bitfield interfaces self-documenting and less error-prone. Code Location: |
Union/Variant Serialization¶
The software shall serialize unions by writing a type identifier field that indicates the active member type, followed by the member data serialized according to its declared type. Rationale: The type field allows the receiver to identify which union member is active. Code Location: |
The software shall deserialize unions by reading the type field first, then dispatching to the appropriate deserializer based on the type identifier. Rationale: Type-based dispatch ensures the correct deserializer is used for the active member. Code Location: |
The software shall pad union members to the largest member size when the union is configured for uniform sizing. The padding bytes shall be zero. Rationale: Uniform padding enables fixed-offset access regardless of active member. Code Location: |
The software shall support configurable union length fields of 0, 8, 16, or 32 bits. Default is 32 bits. A length of 0 means no length field. The length field does not include itself or the type field. Rationale: Configurable length fields support varying union serialization formats across interfaces. Code Location: |
The software shall support configurable union type fields of 8, 16, or 32 bits. Default is 32 bits. The order of length and type fields shall be configurable. Rationale: Configurable type fields and ordering support interface-specific union formats. Code Location: |
The software shall enforce that when the union length field is 0 bits, all types must have the same length. If types have different lengths, the implementation shall warn and pad shorter elements with zeros. Rationale: Zero-length unions with different-sized members need padding to maintain fixed size. Code Location: |
Optional Parameter Serialization¶
The software shall serialize optional parameters as arrays with 0 to 1 elements. Rationale: Modeling optionals as 0-1 arrays reuses existing array serialization infrastructure. Code Location: |
Multidimensional Array Serialization¶
The software shall serialize multidimensional arrays following the C++ row-major memory layout order. Rationale: Row-major order matches C++ memory layout for zero-copy compatibility. Code Location: |
The software shall use multiple length fields for multidimensional dynamic arrays. Maximum length per dimension shall be defined by the interface specification for static buffer allocation. Rationale: Per-dimension length fields support ragged multidimensional arrays. Code Location: |
The software shall support configurable dynamic array length fields of 0, 8, 16, or 32 bits as defined by the interface specification. Rationale: Configurable length field size balances overhead vs maximum array capacity. Code Location: |
Advanced String Serialization¶
The software shall support UTF-16BE and UTF-16LE string encodings. UTF-16 strings shall be zero-terminated with at least two 0x00 bytes, have even length, and ignore the last byte if odd-length. Rationale: UTF-16 support enables compatibility with interfaces requiring 16-bit character encoding. Code Location: |
The software shall validate the Byte Order Mark (BOM) against the interface specification and handle BOM mismatches as errors. Rationale: BOM validation ensures the receiver interprets string encoding correctly. Code Location: |
The software shall serialize fixed-length strings with null-termination and BOM. If alignment is specified, strings shall be padded with null characters to meet the alignment. Rationale: Fixed-length strings provide deterministic buffer sizes for safety-critical systems. Code Location: |
The software shall serialize strings using the encoding specified in the interface specification (UTF-8, UTF-16BE, or UTF-16LE). Rationale: Encoding specification ensures sender and receiver agree on character interpretation. Code Location: |
Struct Length Field¶
The software shall support an optional length field of 8, 16, or 32 bits prepended to a struct as defined by the interface specification. If not specified, no length field is used. Extra bytes beyond the known struct length shall be skipped. Rationale: Struct length fields enable receivers to skip unknown trailing members for forward compatibility. Code Location: |
Serialization Warnings¶
The software’s code generation toolchain shall warn about misaligned structs but shall not fail code generation. Rationale: Warnings alert developers to potential performance issues without blocking code generation. Code Location: |
The software shall handle serialization of enum values outside the defined range according to configuration. Rationale: Out-of-range enum values may indicate data corruption or version mismatch. Error Handling: If strict mode: return INVALID_VALUE. If lenient: serialize as underlying integer. Code Location: |
The software shall return an error when deserializing a union with an unknown type identifier. Rationale: Unknown type IDs prevent correct deserialization of the union data. Error Handling: Return INVALID_TYPE_ID error code. Code Location: |
The software shall return an error when the union data size does not match the expected size for the declared type. Rationale: Size mismatch indicates data corruption or version incompatibility. Error Handling: Return MALFORMED_DATA error code. Code Location: |
The software shall return an error when a string’s declared length exceeds the remaining buffer data. Rationale: Prevents buffer overread from malicious or corrupted length fields. Error Handling: Return INSUFFICIENT_DATA error code. Code Location: |
The software shall reject dynamic arrays whose declared length exceeds a configurable maximum to prevent excessive memory allocation. Rationale: Unbounded allocation from untrusted length fields is a denial-of-service vector. Error Handling: Return ARRAY_TOO_LARGE error code without allocating memory. Code Location: |
The software shall return an error when the remaining buffer is insufficient for the expected fixed-array size. Rationale: Incomplete fixed arrays cannot be partially deserialized. Error Handling: Return INSUFFICIENT_DATA error code. Code Location: |
The software shall return an error when alignment padding would exceed the buffer capacity. Rationale: Alignment must respect buffer boundaries. Error Handling: Return BUFFER_OVERFLOW error code. Code Location: |
The software shall detect and handle signed integer values that exceed the range of the target type. Rationale: Overflow in signed integers produces implementation-defined behavior. Error Handling: Truncate to valid range or return OVERFLOW error based on configuration. Code Location: |
The software shall preserve NaN bit patterns through serialization without treating NaN as equal to any value. Rationale: NaN has special comparison semantics that must be preserved. Error Handling: No error; preserve bit pattern faithfully. Code Location: |
The software shall handle strings with embedded null bytes according to configuration. Rationale: Embedded nulls can cause string truncation in C-style string handling. Error Handling: Truncate at first null (default) or preserve full length based on config. Code Location: |
The software shall limit array nesting depth to prevent stack overflow during recursive serialization. Rationale: Unbounded recursion from deeply nested structures causes stack overflow. Error Handling: Return NESTING_TOO_DEEP error code. Code Location: |
The software shall reject read operations when the internal position is beyond the buffer boundary. Rationale: Position beyond buffer indicates a programming error. Error Handling: Return INVALID_STATE error code. Code Location: |
The software shall prevent integer overflow when calculating alignment positions. Rationale: Repeated alignment could overflow the position counter. Error Handling: Check for overflow before adding padding. Code Location: |
Traceability¶
Implementation Files¶
include/serialization/serializer.h- Serializer/Deserializer interfacessrc/serialization/serializer.cpp- Serialization implementation
Test Files¶
tests/test_serialization.cpp- Serialization unit tests