Skip to main content

Crate simple_someip

Crate simple_someip 

Source
Expand description

§Simple SOME/IP

CI Coverage Crates.io

A Rust implementation of the SOME/IP automotive communication protocol — remote procedure calls, event notifications, service discovery, and wire-format serialization.

The core protocol layer (protocol, e2e, and trait modules) is no_std-compatible with zero heap allocation, making it suitable for embedded targets. Optional client and server modules provide async tokio-based networking for std environments.

§Modules

Moduleno_stdDescription
protocolYesWire format: headers, messages, message types, return codes, and service discovery (SD) entries/options
e2eYesEnd-to-End protection — Profile 4 (CRC-32) and Profile 5 (CRC-16)
WireFormat / PayloadWireFormatYesTraits for serializing messages and defining custom payload types
[client]NoAsync tokio client — service discovery, subscriptions, and request/response (feature client)
[server]NoAsync tokio server — service offering, event publishing, and subscription management (feature server)

§Feature Flags

FeatureDefaultDescription
clientnoAsync tokio client; implies std + tokio + socket2
servernoAsync tokio server; implies std + tokio + socket2
stdnoEnables std-dependent helpers

By default only the protocol, trait, and e2e modules are compiled, and the crate builds in no_std mode with no allocator requirement.

§Examples

§Encoding a SOME/IP-SD header (no_std)

use simple_someip::WireFormat;
use simple_someip::protocol::sd::{self, Entry, ServiceEntry};

// Build an SD header with a FindService entry
let entries = [Entry::FindService(ServiceEntry::find(0x1234))];
let sd_header = sd::Header::new(sd::Flags::new_sd(false), &entries, &[]);

// Encode to bytes
let mut buf = [0u8; 64];
let n = sd_header.encode(&mut buf.as_mut_slice()).unwrap();

// Decode from bytes (zero-copy view)
let view = sd::SdHeaderView::parse(&buf[..n]).unwrap();
assert_eq!(view.entry_count(), 1);

§Async client (requires feature = "client")

use simple_someip::{Client, ClientUpdate, RawPayload};

#[tokio::main]
async fn main() {
    // Client::new returns a Clone-able handle and an update stream.
    let (client, mut updates) = Client::<RawPayload>::new([192, 168, 1, 100].into());
    client.bind_discovery().await.unwrap();

    while let Some(update) = updates.recv().await {
        match update {
            ClientUpdate::DiscoveryUpdated(msg) => { /* SD message received */ }
            ClientUpdate::Unicast { message, e2e_status } => { /* unicast reply */ }
            ClientUpdate::SenderRebooted(addr) => { /* remote reboot */ }
            ClientUpdate::Error(err) => { /* error */ }
        }
    }
}

§References

Re-exports§

pub use e2e::E2ECheckStatus;
pub use e2e::E2EKey;
pub use e2e::E2EProfile;

Modules§

e2e
End-to-end (E2E) protection utilities for SOME/IP payloads. E2E (End-to-End) protection for SOME/IP payloads.
protocol
SOME/IP protocol primitives: headers, messages, return codes, and service discovery.

Traits§

PayloadWireFormat
A trait for SOME/IP Payload types that can be serialized to a Writer and constructed from raw payload bytes.
WireFormat
A trait for types that can be serialized to a Writer.