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...
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

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

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

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

A memcomparable serialization format.

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

PyO3's PyAny as a serde data format

serde-pyobject PyO3's PyAny as a serde data format Usage Serialize T: Serialize into &'py PyAny: use serde::Serialize; use pyo3::{Python, types::{PyAn

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

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.

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

Tight Model format is a lossy 3D model format focused on reducing file size as much as posible without decreasing visual quality of the viewed model or read speeds.
Tight Model format is a lossy 3D model format focused on reducing file size as much as posible without decreasing visual quality of the viewed model or read speeds.

What is Tight Model Format The main goal of the tmf project is to provide a way to save 3D game assets compressed in such a way, that there are no not

Given a set of kmers (fasta format) and a set of sequences (fasta format), this tool will extract the sequences containing the kmers.

Kmer2sequences Description Given a set of kmers (fasta / fastq [.gz] format) and a set of sequences (fasta / fastq [.gz] format), this tool will extra

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

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
Esri JSON struct definitions and serde integration.

serde_esri Esri JSON parsing library. This crate provides representations of Esri JSON objects with serde::Deserialize and serde::Serialize trait impl

Josiah Parry 5 Nov 23, 2023
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
Serialize JSON into a canonical format.

json-canon Serialize JSON into a canonical format. Safe for generating a consistent cryptographic hash or signature across platforms. Follows RFC8785:

Mikey 14 May 30, 2023
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
A Rust library that simplifies YAML serialization and deserialization using Serde.

Serde YML: Seamless YAML Serialization for Rust Serde YML is a Rust library that simplifies YAML serialization and deserialization using Serde. Effort

Sebastien Rousseau 4 Apr 4, 2024
axum-serde is a library that provides multiple serde-based extractors and responders for the Axum web framework.

axum-serde ?? Overview axum-serde is a library that provides multiple serde-based extractors / responses for the Axum web framework. It also offers a

GengTeng 3 Dec 12, 2023