OSAL-RS-Serde
An extensible serialization/deserialization framework for Rust, inspired by Serde but optimized for embedded systems and no-std environments.
Features
- ✅ No-std compatible: Works perfectly in bare-metal environments
- ✅ Memory-efficient: Optimized for resource-constrained systems
- ✅ Extensible: Easy to create custom serializers for any format
- ✅ Derive Macro: Support for
#[derive(Serialize, Deserialize)] - ✅ Type-safe: Leverages Rust's type system
- ✅ Reusable: Can be used in any project, not just with osal-rs
Supported Types
Primitives
- Integers:
u8,i8,u16,i16,u32,i32,u64,i64,u128,i128 - Floats:
f32,f64 - Boolean:
bool
Compound
- Arrays:
[T; N] - Tuples:
(T1, T2),(T1, T2, T3) - Option:
Option<T>
Custom
- Any struct with
#[derive(Serialize, Deserialize)]
Memory Sizes
bool: 1 byte
u8/i8: 1 byte
u16/i16: 2 bytes
u32/i32: 4 bytes
u64/i64: 8 bytes
u128/i128: 16 bytes
f32: 4 bytes
f64: 8 bytes
Option<T>: 1 byte (tag) + sizeof(T) if Some, 1 byte if None
Array[T;N]: sizeof(T) * N
Tuple: sum(sizeof each field)
Installation
Add to your Cargo.toml:
[]
= { = "0.3", = ["derive"] }
Available features:
alloc: Enables dynamic allocation support (included indefault)std: Enables standard library supportderive: Enables#[derive(Serialize, Deserialize)]macros
Project Structure
The osal-rs-serde crate includes:
- Core library: Traits and implementations for serialization/deserialization
- Derive macros (optional): Procedural macros for automatic derivation (in
derive/)
Everything is contained in a single package for ease of use.
Usage
With Derive Macros (Recommended)
use ;
Manual Implementation
use ;
Usage with OSAL-RS Queue
use ;
use ;
Supported Types
The framework automatically supports:
- Primitive types:
bool,u8,i8,u16,i16,u32,i32,u64,i64,u128,i128 - Floating point:
f32,f64 - Arrays:
[T; N] - Tuples:
(T1, T2),(T1, T2, T3) - Option:
Option<T> - Any custom type that implements
Serialize/Deserialize
Custom Serializers
You can create custom serializers to support different formats:
use ;
Examples
See the examples/ folder for complete examples:
# Basic example
# With derive macros
# Integration with OSAL-RS
Comparison with Serde
| Feature | osal-rs-serde | serde |
|---|---|---|
| No-std | ✅ | ✅ |
| Derive macro | ✅ | ✅ |
| Binary size | Small | Medium/Large |
| Supported formats | Customizable | Many built-in |
| Target | Embedded/RTOS | General purpose |
License
GPL-3.0 - See LICENSE for details.
Author
Antonio Salsi passy.linux@zresa.it