7 releases (2 stable)

1.2.0 Aug 20, 2024
1.0.0 Mar 21, 2024
0.1.5 Feb 15, 2024
0.1.3 Mar 1, 2023
0.1.0 Jun 14, 2021

#4 in #encodable

Download history 87/week @ 2024-11-30 129/week @ 2024-12-07 107/week @ 2024-12-14 43/week @ 2024-12-21 22/week @ 2024-12-28 57/week @ 2025-01-04 62/week @ 2025-01-11 111/week @ 2025-01-18 637/week @ 2025-01-25 1310/week @ 2025-02-01 1390/week @ 2025-02-08 1969/week @ 2025-02-15 2005/week @ 2025-02-22 2162/week @ 2025-03-01 1754/week @ 2025-03-08 1356/week @ 2025-03-15

7,496 downloads per month
Used in 13 crates (2 directly)

MIT license

125KB
3K SLoC

binary_codec_sv2

crates.io
docs.rs
rustc+
license codecov

binary_codec_sv2 is a no_std Rust crate that helps serialize and de-serialize binary data into and from Stratum V2 types.

Key Features

  • Comprehensive Encoding and Decoding: Provides traits (Encodable, Decodable) for converting between Rust and SV2 data types/structures.
  • Support for Complex Data Structures: Handles primitives, nested structures, and protocol-specific types like U24, U256,Str0255 and rest.
  • Error Handling: Robust mechanisms for managing encoding/decoding failures, including size mismatches and invalid data.
  • Cross-Language Compatibility: Utilities like CVec and CError ensure smooth integration with other programming languages.
  • no_std Compatibility: Fully supports constrained environments without the Rust standard library.

Sv2 Type Mapping

The crate supports the following mappings between Rust and SV2 types

Rust Type Sv2 Type
bool BOOL
u8 U8
u16 U16
U24 U24
u32 U32
u64 U64
f32 F32
Str0255 STRO_255
Signature SIGNATURE
[u8] BYTES
Seq0255 SEQ0_255[T]
Seq064K SEQ0_64K[T]

Installation

Add binary_codec_sv2 to your project by running:

cargo add binary_codec_sv2

Dependencies

~0–375KB