Crate someip_wire

Crate someip_wire 

Source
Expand description

§SOME/IP-wire

This crate provides the means for parsing byte arrays into higher-level SOME/IP representations, and vice versa. It is designed to be used in embedded environments and is a no_std crate by default.

§Scope

This crate focuses solely on SOME/IP header parsing and serialization.

The crate parses the standardized 16-byte SOME/IP header and provides the payload data as a raw byte slice. It does NOT parse the payload content itself, as payload format is entirely application-specific and defined by service interface definitions (e.g., FIDL/Franca IDL).

To use this crate in a complete SOME/IP stack, you need to:

  1. Use this crate to parse/emit SOME/IP headers
  2. Implement your own payload parser/serializer based on your service definitions
  3. Connect service/method IDs to their respective payload handlers

This separation keeps the crate focused, lightweight, and universally applicable across different SOME/IP service implementations.

§Features

  • no_std compatible by default
  • Zero-allocation parsing and serialization
  • Support for all SOME/IP message types
  • Clean enum-based API for return codes and message types
  • Wire format using simple u8 for efficiency

§Examples

§Parsing a SOME/IP packet

use someip_wire::packet::Packet;
use someip_wire::payload::Repr;
use someip_wire::types::{MessageId, RequestId, MessageType, ReturnCode};

// Example SOME/IP packet bytes (16-byte header + payload)
let buffer = [
    0x12, 0x34, 0x00, 0x01, // Message ID (service 0x1234, method 0x0001)
    0x00, 0x00, 0x00, 0x10, // Length
    0x00, 0x01, 0x00, 0x00, // Request ID (client 0x0001, session 0x0000)
    0x01,                   // Protocol version
    0x01,                   // Interface version
    0x00,                   // Message type (Request)
    0x00,                   // Return code (E_OK)
    // Payload data follows...
    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
];

let packet = Packet::new_unchecked(&buffer);
let repr = Repr::parse(&packet).unwrap();

assert_eq!(repr.message_type, MessageType::Request);
assert_eq!(repr.return_code, ReturnCode::E_OK);
assert_eq!(repr.protocol_version, 0x01);
assert_eq!(repr.data.len(), 8);

§Creating and emitting a SOME/IP packet

use someip_wire::packet::Packet;
use someip_wire::payload::Repr;
use someip_wire::types::{MessageId, RequestId, ClientId, MessageType, ReturnCode};

// Use Repr::new() to automatically calculate the length field
let repr = Repr::new(
    MessageId { service_id: 0x1234, method_id: 0x0001 },
    RequestId {
        client_id: ClientId { client_id_prefix: 0x00, client_id: 0x01 },
        session_id: 0x0000,
    },
    0x01, // protocol_version
    0x01, // interface_version
    MessageType::Response,
    ReturnCode::E_OK,
    &[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08],
);

// The length field is automatically set to 16 (8 header + 8 payload)
assert_eq!(repr.length, 16);

let mut buffer = [0u8; 24]; // 16-byte header + 8-byte payload
let mut packet = Packet::new_unchecked(&mut buffer);
repr.emit(&mut packet);

assert_eq!(packet.message_type(), 0x03); // Response
assert_eq!(packet.return_code(), 0x00); // E_OK

§Working with return codes

use someip_wire::types::ReturnCode;

// Named return codes
let ok = ReturnCode::E_OK;
let error = ReturnCode::E_NOT_OK;
let timeout = ReturnCode::E_TIMEOUT;

// Reserved ranges
let someip_reserved = ReturnCode::ReservedSomeIP(0x15);
let service_reserved = ReturnCode::ReservedServiceMethod(0x30);

// Convert to/from u8
assert_eq!(ok.as_u8(), 0x00);
assert_eq!(ReturnCode::from_u8(0x01), Some(ReturnCode::E_NOT_OK));

// Check return code properties
assert!(ok.is_ok());
assert!(someip_reserved.is_reserved_someip());
assert!(service_reserved.is_reserved_service_method());

§Modules

  • error: Contains the error type for SOME/IP packet parsing
  • field: Contains the field definitions for the SOME/IP header
  • packet: Contains the Packet type for low-level packet access (wire format)
  • payload: Contains the Repr type for high-level SOME/IP representation
  • types: Contains SOME/IP type definitions (MessageId, RequestId, ReturnCode, MessageType)

§Architecture

The crate uses a two-layer architecture:

  • Wire format layer (packet): Works directly with u8 values for efficiency
  • Representation layer (payload, types): Provides clean enums and type-safe APIs

This design ensures zero-cost abstractions while maintaining a pleasant developer experience.

Modules§

error
field
packet
Packet module
payload
types