#protobuf #codec #proto #no-alloc

no-std femtopb

A no-std, no-alloc set of tools for protobuf encoding and decoding

12 unstable releases (3 breaking)

0.5.0 Aug 1, 2024
0.4.5 Apr 19, 2024
0.3.0 Apr 4, 2024
0.2.0 Apr 3, 2024
0.1.4 Apr 3, 2024

#324 in Encoding

Download history 224/week @ 2024-08-18 1254/week @ 2024-08-25 715/week @ 2024-09-01 575/week @ 2024-09-08 621/week @ 2024-09-15 680/week @ 2024-09-22 374/week @ 2024-09-29 319/week @ 2024-10-06 401/week @ 2024-10-13 841/week @ 2024-10-20 192/week @ 2024-10-27 359/week @ 2024-11-03 300/week @ 2024-11-10 546/week @ 2024-11-17 1078/week @ 2024-11-24 568/week @ 2024-12-01

2,510 downloads per month

Apache-2.0

115KB
2.5K SLoC

femtopb

A tiny footprint, #[no_std], no-alloc, no-panic Protobuf serialization library. This allows you to communicate using Protobuf on constrained platforms, like bare-metal MCUs with very limited RAM.

Yes, you heard it right: this library lets you serialize and deserialize Protobuf messages without any dynamic memory/heap allocation.

The library takes care of using simple types with limited use of generics when possible, to avoid monomorphization code size explosion. The runtime also consists of many tiny functions so that the ones that aren't used can get optimized away.

During testing of this crate, checks are made to ensure that femtopb code cannot panic. If you want to leverage the no-panic checks yourself to debug your own project, enable the assert-no-panic crate feature. It is not necessarily a good idea to enable this feature for your release code, as enabling this feature might change the generated code slightly.

There are some limitations, however. Messages must be deserialized from continuous &[u8] slices, so incremental deserialization from other bytes::Buf types or streams/files/sockets/... is not supported. Also, messages borrow their source slice for the duration of their lifetime. Deserialization of repeated fields happens lazily to avoid having to dynamically allocate a Vec-like data structure.

The library does not implement advanced features like Protobuf reflection or well-known types, etc. For that, use the prost crate. It is probably advisable to use prost for applications where it is possible, and only use femtopb on platforms where it is necessary.

Attribution

The API is heavily inspired by the prost crate, which is licensed under the Apache 2.0 license. Some tests and key algorithms have also been copied from that crate. This crate is also licensed under the Apache 2.0 license.

Dependencies

~215–710KB
~17K SLoC