Crate binary_sv2

Source
Expand description

Export custom implementations of the binary_sv2 protocol, enabling encoding and decoding through custom traits.

§Overview

This crate will re-export implementations of theDeserialize and Serialize traits from a custom implementation provided by binary_codec_sv2 and derive_codec_sv2. This allows for flexible integration of SV2 protocol types and binary serialization.

§Features

  • prop_test: Adds support for property testing for protocol types.
  • with_buffer_pool: Enables support for buffer pooling to optimize memory usage during serialization and deserialization.

Re-exports§

pub use binary_codec_sv2;

Modules§

decodable
Provides an interface and implementation details for decoding complex data structures from raw bytes or I/O streams. Handles deserialization of nested and primitive data structures through traits, enums, and helper functions for managing the decoding process.
encodable
Provides an encoding framework for serializing various data types into bytes.

Structs§

CVec
A struct to facilitate transferring a Vec<u8> across FFI boundaries.
CVec2
A struct to manage a collection of CVec objects across FFI boundaries.
Seq0255
Seq0255 represents a sequence with a maximum length of 255 elements. This structure uses a generic type T and a lifetime parameter 'a.
Seq064K
Seq064K represents a sequence with a maximum length of 65535 elements. This structure uses a generic type T and a lifetime parameter 'a.
Sv2Option
The lifetime ’a is defined.
U24
Represents a 24-bit unsigned integer (U24), supporting SV2 serialization and deserialization. Only first 3 bytes of a u32 is considered to get the SV2 value, and rest are ignored (in little endian).

Enums§

CError
CError is a foreign function interface (FFI)-compatible version of the Error enum to facilitate cross-language compatibility.
EncodableField
The EncodableField enum defines encodable fields, which may be a primitive or struct.
Error
Error types used within the protocol library to indicate various failure conditions.

Traits§

Decodable
Custom deserialization of types from binary data.
Deserialize
Custom deserialization of types from binary data.
Encodable
The Encodable trait defines the interface for encoding a type into bytes.
Fixed
Fixed is a trait is defining a single element representing a size of a constant.
GetMarker
Trait for retrieving the FieldMarker associated with a type.
GetSize
GetSize is a trait defining a single function that calculates the total size of an encodable type.
Serialize
The Encodable trait defines the interface for encoding a type into bytes.
SizeHint
The SizeHint trait provides a mechanism to return the encoded bytes size of a decodable type.
Sv2DataType
Sv2DataType is a trait that defines methods for encoding and decoding Stratum V2 data. It is used for serializing and deserializing both fixed-size and dynamically-sized types.

Functions§

_c_export_cvec
Exported FFI functions for interoperability with C code for CVec
_c_export_cvec2
Exported FFI functions for interoperability with C code for CVec2
_c_export_u24
Exported FFI functions for interoperability with C code for u24
clone_message
Does nothing and will be removed during refactor
cvec2_push
Adds a CVec to a CVec2.
cvec_from_buffer
Creates a CVec from a buffer that was allocated in C.
free_vec
Frees the underlying memory of a CVec.
free_vec_2
Frees the underlying memory of a CVec2 and all its elements.
from_bytes
Decodes an SV2-encoded byte slice into the specified data type.
init_cvec2
Initializes an empty CVec2.
to_bytes
Converts the provided SV2 data type to a byte vector based on the SV2 encoding format.
to_writer
Encodes the SV2 data type to the provided byte slice.
u256_from_int
Converts a value implementing the Into<u64> trait into a custom U256 type.

Type Aliases§

B016M
Type alias for a variable-sized byte array with a maximum size of ~16 MB, represented using the Inner type with a 3-byte header.
B0255
Type alias for a variable-sized byte array with a maximum size of 255 bytes, represented using the Inner type with a 1-byte header.
B032
Type alias for a variable-sized byte array with a maximum size of 32 bytes, represented using the Inner type with a 1-byte header.
B064K
Type alias for a variable-sized byte array with a maximum size of 64 KB, represented using the Inner type with a 2-byte header.
PubKey
Type alias for a 32-byte public key represented using the Inner type with fixed-size configuration.
Signature
Type alias for a 64-byte cryptographic signature represented using the Inner type with fixed-size configuration.
Str0255
Type alias for a variable-sized string with a maximum size of 255 bytes, represented using the Inner type with a 1-byte header.
U32AsRef
Type alias for a 4-byte slice or owned data represented using the Inner type with fixed-size configuration.
U256
Type alias for a 32-byte slice or owned data (commonly used for cryptographic hashes or IDs) represented using the Inner type with fixed-size configuration.

Derive Macros§

Deserialize
Derives the Decodable trait, generating implementations for deserializing a struct from a byte stream, including its structure, field decoding, and a method for creating a static version.
Serialize
Derives the Encodable trait, generating implementations for serializing a struct into an encoded format, including methods for field serialization, calculating the encoded size, and handling cases where the struct is already sized.