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 typeT
and a lifetime parameter'a
.- Seq064K
Seq064K
represents a sequence with a maximum length of 65535 elements. This structure uses a generic typeT
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 theError
enum to facilitate cross-language compatibility.- Encodable
Field - 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. - Size
Hint - The
SizeHint
trait provides a mechanism to return the encoded bytes size of a decodable type. - Sv2Data
Type 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 aCVec2
. - 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 customU256
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. - U32As
Ref - 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.