A SOME/IP serialization format using the serde framework

Overview

serde_someip implements SOME/IP ontop of serde

use serde::{Serialize, Deserialize};
use serde_someip::SomeIp;
use serde_someip::options::ExampleOptions;

#[derive(Serialize, Deserialize, Debug, SomeIp)]
struct Point {
    #[someip(id = 0)]
    x: i32,
    #[someip(id = 1)]
    y: i32,
}

fn main() {
    let point = Point { x: 1, y: 2 };

    // Encode the message using someip.
    let serialized = serde_someip::to_vec::<ExampleOptions, _>(&point).unwrap();

    // Prints serialized = [0x20, 0, 0, 0 , 0, 1, 0x20, 1, 0, 0, 0, 2]
    println!("serialized = {:?}", serialized);

    //Decode the message using someip
    let deserialized: Point = serde_someip::from_slice::<ExampleOptions, _>(&serialized).unwrap();

    // Prints deserialized = Point { x: 1, y: 2 }
    println!("deserialized = {:?}", deserialized);
}
You might also like...
A memcomparable serialization format.

memcomparable A memcomparable serialization format. The memcomparable format allows comparison of two values by using the simple memcmp function. Inst

Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.

Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.

Msgpack serialization/deserialization library for Python, written in Rust using PyO3, and rust-msgpack. Reboot of orjson. msgpack.org[Python]

ormsgpack ormsgpack is a fast msgpack library for Python. It is a fork/reboot of orjson It serializes faster than msgpack-python and deserializes a bi

Serialize & deserialize device tree binary using serde

serde_device_tree Use serde framework to deserialize Device Tree Blob binary files; no_std compatible. Use this library Run example: cargo run --examp

Provides a wrapper to deserialize clap app using serde.

clap-serde Provides a wrapper to deserialize clap app using serde. API Reference toml const CLAP_TOML: &'static str = r#" name = "app_clap_serde" vers

convert CHAIN format to PAF format

convert CHAIN format to PAF format

Astro Format is a library for efficiently encoding and decoding a set of bytes into a single buffer format.

Astro Format is a library for efficiently transcoding arrays into a single buffer and native rust types into strings

Convert an MCU register description from the EDC format to the SVD format

edc2svd Convert an MCU register description from the EDC format to the SVD format EDC files are used to describe the special function registers of PIC

tnetstring serialization library for rust.

TNetStrings: Tagged Netstrings This module implements bindings for the tnetstring serialization format. API let t = tnetstring::str("hello world"); le

openapi schema serialization for rust

open api Rust crate for serializing and deserializing open api documents Documentation install add the following to your Cargo.toml file [dependencies

Benchmarks for rust serialization frameworks

Rust serialization benchmark The goal of these benchmarks is to provide thorough and complete benchmarks for various rust serialization frameworks. Th

Lazy Binary Serialization

LBS crates.io | docs.rs Library name stands for Lazy Binary Serialization. We call it "lazy" because it does not serizalize/deserialize struct fields

Alkahest - Fantastic serialization library.

Alkahest is serialization library aimed for packet writing and reading in hot path. For this purpose Alkahest avoids allocations and reads data only on demand.

A simple entity-component-system crate for rust with serialization support

Gallium A simple entity-component-system crate for rust with serialization support Usage You can include the library using carge: [dependencies] galli

Fast binary serialization with versioning.

BinVerSe (Binary Versioned Serializer) Provides fast binary serialization with versioning to store data in a backwards-compatible, compact way. Right

A rustic tcp + serialization abstraction.

Wire An abstraction over TCP and Serialization "put a struct in one side and it comes out the other end" Wire is a library that makes writing applicat

WebAssembly serialization/deserialization in rust

parity-wasm Low-level WebAssembly format library. Documentation Rust WebAssembly format serializing/deserializing Add to Cargo.toml [dependencies] par

Deser: an experimental serialization and deserialization library for Rust

deser: an experimental serialization and deserialization library for Rust Deser is an experimental serialization system for Rust. It wants to explore

Library with support for de/serialization, parsing and executing on data-structures and network messages related to Bitcoin
Library with support for de/serialization, parsing and executing on data-structures and network messages related to Bitcoin

Rust Bitcoin Library with support for de/serialization, parsing and executing on data-structures and network messages related to Bitcoin. Heads up for

Comments
  • UTF16LE support

    UTF16LE support

    Hey just wanted to run a client using serde_someip against the CommonAPI - HelloWorld Example and ran into the issue that it by default uses utf16le.

    On the server side of the default example I see a : [CAPI][ERROR] MethodWithReplyStubDispatcher (someip): deserialization failed! [4660.22136.30000.1] on the client side I specified: serde_someip::options::StringEncoding::Utf16.

    So changing this to utf8 (in the example service fdepl) and with following SomeIpOptions in the client it works great:

    pub struct VSomeIpDefaultOptions {}
    impl SomeIpOptions for VSomeIpDefaultOptions {
        const BYTE_ORDER: serde_someip::options::ByteOrder =
            serde_someip::options::ByteOrder::BigEndian;
        const STRING_WITH_BOM: bool = true;
        const STRING_ENCODING: serde_someip::options::StringEncoding =
            serde_someip::options::StringEncoding::Utf8;
        const STRING_WITH_TERMINATOR: bool = true;
        const DEFAULT_LENGTH_FIELD_SIZE: Option<serde_someip::length_fields::LengthFieldSize> =
            Some(serde_someip::length_fields::LengthFieldSize::FourBytes);
        const SERIALIZER_USE_LEGACY_WIRE_TYPE: bool = true;
        const SERIALIZER_LENGTH_FIELD_SIZE_SELECTION: serde_someip::options::LengthFieldSizeSelection =
            serde_someip::options::LengthFieldSizeSelection::AsConfigured;
        const DESERIALIZER_STRICT_BOOL: bool = false;
        const DESERIALIZER_ACTION_ON_TOO_MUCH_DATA: serde_someip::options::ActionOnTooMuchData =
            serde_someip::options::ActionOnTooMuchData::Discard;
    }
    

    So I looked into the serde_someip implementation and compared it to the CommonApi Someip one and the issues I currently see.

    • StringEncoding does not allow specifying a separate endianness compared to the overall BYTE_ORDER. So not sure how much sense this requirements makes but in this case the example seems to use a different endianness for string encoding.

    • UTF16 String BOM seems to depend on endianness, but in serialize_str BOM always writes the BOM for UTF-16 BE: Wikipedia BOM capicxx-someip-runtime _writeBom

    opened by marcelbuesing 4
  • vsomeip SomeIpOptions

    vsomeip SomeIpOptions

    First of all, thanks for making this crate available, it's really awesome work. I really like the idea to base this on serde and also the convenience and readability it brings.

    I am currently trying out this crate in a client that talks to a service that uses vsomeip. I assume this might be a common use case. So I thought I'd share the SomeIpOptions implementations that worked for me, hoping that it will relieve the next one who tries this from digging in the common someip runtime code.

    This assumes common someip runtime defaults (_dep == nullptr) and may need some tweaking depending on ones custom configuration.

    pub struct VSomeIpDefaultOptions {}
    
    impl SomeIpOptions for VSomeIpDefaultOptions {
        const BYTE_ORDER: serde_someip::options::ByteOrder = serde_someip::options::ByteOrder::BigEndian;
    
        // https://github.com/COVESA/capicxx-someip-runtime/blob/0ad2bdc1807fc0f078b9f9368a47ff2f3366ed13/src/CommonAPI/SomeIP/OutputStream.cpp#L368
        const STRING_WITH_BOM: bool = true;
    
        const STRING_ENCODING: serde_someip::options::StringEncoding = serde_someip::options::StringEncoding::Utf8;
    
        // https://github.com/COVESA/capicxx-someip-runtime/blob/0ad2bdc1807fc0f078b9f9368a47ff2f3366ed13/src/CommonAPI/SomeIP/OutputStream.cpp#L228
        const STRING_WITH_TERMINATOR: bool = true;
    
        // https://github.com/COVESA/capicxx-someip-runtime/blob/0ad2bdc1807fc0f078b9f9368a47ff2f3366ed13/src/CommonAPI/SomeIP/OutputStream.cpp#L246
        const DEFAULT_LENGTH_FIELD_SIZE: Option<serde_someip::length_fields::LengthFieldSize> = Some(serde_someip::length_fields::LengthFieldSize::FourBytes);
        
        // https://github.com/COVESA/capicxx-someip-runtime/blob/0ad2bdc1807fc0f078b9f9368a47ff2f3366ed13/src/CommonAPI/SomeIP/OutputStream.cpp#L246
        const OVERWRITE_LENGTH_FIELD_SIZE: Option<serde_someip::length_fields::LengthFieldSize> = Some(serde_someip::length_fields::LengthFieldSize::FourBytes);
    
        const SERIALIZER_USE_LEGACY_WIRE_TYPE: bool = false;
    
        const SERIALIZER_LENGTH_FIELD_SIZE_SELECTION: serde_someip::options::LengthFieldSizeSelection =
            serde_someip::options::LengthFieldSizeSelection::AsConfigured;
    
        const DESERIALIZER_STRICT_BOOL: bool = false;
    
        const DESERIALIZER_ACTION_ON_TOO_MUCH_DATA: serde_someip::options::ActionOnTooMuchData = serde_someip::options::ActionOnTooMuchData::Fail;
    }
    

    I had one interesting case when using ActionOnTooMuchData::Discard that I ran into CannotCodeString("String muse end with 0 terminator") because I had specified the max_size in Rust too short and the terminator was basically discarded. Even worse the difference between max_size and actual size was only the terminator in my case, so setting STRING_WITH_TERMINATOR to false magically made the deserialization work ;). One could say that is the definition of Discard , I'm just leaving it here for the next one who runs into this.

    opened by marcelbuesing 2
  • Derive fails for struct with typedefed sequence

    Derive fails for struct with typedefed sequence

    The following code fails to compile with: no associated item namedSOMEIP_TYPEfound for structVecin the current scope associated item not found in Vec<u8>

        use serde::{Serialize, Deserialize};
        use serde_someip::SomeIp;
    
        type Bytes = Vec<u8>;
    
        #[derive(Serialize, Deserialize, SomeIp)]
        struct Foo {
           #[someip(id = 1, max_elements = 4096)]
            data: Bytes,
        }
    

    Looks like the type definition is not supported because the struct definition

        #[derive(Serialize, Deserialize, SomeIp)]
        struct Foo {
            #[someip(id = 1, max_elements = 4096)]
            data: Vec<u8>,
        }
    

    works just fine.

    Tested with serde_someip v0.1.1.

    opened by flxo 2
Owner
Morten Mey
Morten Mey
Serialize/Deserialize tch-rs types with serde

tch-serde: Serialize/Deserialize tch-rs types with serde This crate provides {ser,de}ialization methods for tch-rs common types. docs.rs | crates.io U

null 4 Apr 3, 2022
This library implements a type macro for a zero-sized type that is Serde deserializable only from one specific value.

Monostate This library implements a type macro for a zero-sized type that is Serde deserializable only from one specific value. [dependencies] monosta

David Tolnay 125 Dec 26, 2022
An auxiliary library for the serde crate.

An auxiliary library for the serde crate.

Victor Polevoy 98 Jan 2, 2023
Serde serializatsiya va deserializatsiyasi yordamida qilingan VCard JSON generatori

Vicardi Serde serializatsiya va deserializatsiyasi yordamida qilingan VCard JSON generatori Haqida Bizning CCTLD tomonidan ishlab chiqilgan sistema IC

UZINFOCOM 6 Dec 20, 2022
Converts cargo check (and clippy) JSON output to the GitHub Action error format

cargo-action-fmt Takes JSON-formatted cargo check (and cargo clippy) output and formats it for GitHub actions. Examples This tool can be used with a v

Oliver Gould 8 Oct 12, 2022
Easily create dynamic css using json notation

jss! This crate provides an easy way to write dynamic css using json notation. This gives you more convenient than you think. Considering using a dyna

Jovansonlee Cesar 7 May 14, 2022
serde-like serialization and deserialization of static Rust types in XML

static-xml static-xml is a serde-like serialization and deserialization library for XML, currently written as a layer on top of xml-rs. Status: in ear

Scott Lamb 8 Nov 22, 2022
Rust libraries and tools to help with interoperability and testing of serialization formats based on Serde.

The repository zefchain/serde-reflection is based on Facebook's repository novifinancial/serde-reflection. We are now maintaining the project here and

Zefchain Labs 46 Dec 22, 2022
A HTTP Archive format (HAR) serialization & deserialization library, written in Rust.

har-rs HTTP Archive format (HAR) serialization & deserialization library, written in Rust. Install Add the following to your Cargo.toml file: [depende

Sebastian Mandrean 25 Dec 24, 2022
Rust implementation of the Binary Canonical Serialization (BCS) format

Binary Canonical Serialization (BCS) BCS (formerly "Libra Canonical Serialization" or LCS) is a serialization format developed in the context of the D

Zefchain Labs 4 Nov 13, 2022