pub struct DigMessage {
pub msg_type: u8,
pub id: Option<u16>,
pub data: Bytes,
}Expand description
Wire message with raw u8 opcode — handles both Chia (0–107) and DIG (200–219) opcodes.
Same binary layout as chia_protocol::Message:
[u8 msg_type] [bool has_id] [u16 id (if has_id)] [u32 data_len] [u8... data]Use DigMessage::to_bytes / DigMessage::from_bytes for wire serialization.
Use DigMessage::try_into_chia_message to convert to stock Message when the opcode
is a known Chia type.
Fields§
§msg_type: u8Raw wire opcode — no enum restriction.
id: Option<u16>Correlation ID for request/response pairing (same as Message.id).
data: BytesSerialized payload body.
Implementations§
Source§impl DigMessage
impl DigMessage
Sourcepub const MAX_MESSAGE_SIZE: usize
pub const MAX_MESSAGE_SIZE: usize
Protocol-level ceiling on a single message’s declared payload length (bytes).
from_bytes rejects any data_len prefix above this value with None before
slicing/allocating the payload, so a peer cannot force a multi-gigabyte Vec
allocation via a lying (or genuine but oversized) length prefix. Mirrors
chia-protocol’s own message-size ceiling (16 MiB) — comfortably above any
legitimate DIG opcode payload (attestations, checkpoints, block-transaction
batches) while bounding worst-case per-message memory.
Callers MUST still enforce a per-frame size cap at the transport/framing layer
BEFORE buffering an incoming frame into a contiguous &[u8] — this constant
only bounds what from_bytes will accept once a slice already exists; it cannot
stop a transport from reading an unbounded number of bytes off the wire first.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Serialize to wire bytes (same format as Message::to_bytes).
Layout: [u8 msg_type] [u8 has_id (0/1)] [u16 id if present] [u32 data_len] [data...]
Sourcepub fn from_bytes(bytes: &[u8]) -> Option<Self>
pub fn from_bytes(bytes: &[u8]) -> Option<Self>
Deserialize from wire bytes. Accepts any msg_type value — no enum validation.
Returns None if the buffer is too short, the length prefix doesn’t match, or
the declared data_len exceeds Self::MAX_MESSAGE_SIZE.
This is a leaf parser over an already-materialized &[u8]: the MAX_MESSAGE_SIZE
check bounds the allocation this function performs, but it cannot bound how many
bytes a transport read off the wire to build bytes in the first place. Callers
MUST enforce a per-frame size cap at the transport/framing layer before buffering
an incoming frame, so that a peer cannot force unbounded buffering ahead of ever
reaching this function.
Sourcepub fn from_bytes_owned(buf: Vec<u8>) -> Option<Self>
pub fn from_bytes_owned(buf: Vec<u8>) -> Option<Self>
Deserialize from an OWNED byte buffer, moving the payload instead of copying it.
Identical acceptance/rejection rules to Self::from_bytes (same length checks,
same Self::MAX_MESSAGE_SIZE cap, same None on any malformed input) — the
only difference is that when buf already owns its bytes (e.g. a transport that
read the frame directly into a Vec<u8>), the payload is moved into the result
via Vec::drain instead of being copied out of a borrowed &[u8] with to_vec.
Prefer this over from_bytes whenever the caller already has an owned Vec<u8>
and does not need it afterward.
Sourcepub fn from_chia_message(msg: &Message) -> Self
pub fn from_chia_message(msg: &Message) -> Self
Convert from a stock chia_protocol::Message (lossless — opcode stored as u8).
Clones msg.data. Prefer Self::from_chia_message_owned when an owned
Message is available and does not need to be kept afterward.
Sourcepub fn from_chia_message_owned(msg: Message) -> Self
pub fn from_chia_message_owned(msg: Message) -> Self
Convert from an OWNED stock chia_protocol::Message, moving data instead of
cloning it (lossless — opcode stored as u8).
Sourcepub fn try_into_chia_message(&self) -> Option<Message>
pub fn try_into_chia_message(&self) -> Option<Message>
Try to convert to a stock chia_protocol::Message, cloning self.data.
Fails if msg_type is not a valid ProtocolMessageTypes discriminant
(i.e., DIG extension opcodes 200+ will fail here — use DigMessage directly
for those). Prefer Self::into_chia_message when self does not need to be
kept afterward.
Sourcepub fn into_chia_message(self) -> Option<Message>
pub fn into_chia_message(self) -> Option<Message>
Try to convert into a stock chia_protocol::Message BY VALUE, moving self.data
instead of cloning it.
Same failure condition as Self::try_into_chia_message: None when msg_type
is not a valid ProtocolMessageTypes discriminant. On failure self is dropped
(its opcode was not a known Chia type, so there is nothing useful to hand back).
Sourcepub fn is_dig_extension(&self) -> bool
pub fn is_dig_extension(&self) -> bool
Whether this message carries a DIG extension opcode (>= 200).
Sourcepub fn is_chia_standard(&self) -> bool
pub fn is_chia_standard(&self) -> bool
Whether this message carries a standard Chia opcode (< 200).
Trait Implementations§
Source§impl Clone for DigMessage
impl Clone for DigMessage
Source§fn clone(&self) -> DigMessage
fn clone(&self) -> DigMessage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DigMessage
impl Debug for DigMessage
impl Eq for DigMessage
Source§impl PartialEq for DigMessage
impl PartialEq for DigMessage
impl StructuralPartialEq for DigMessage
Auto Trait Implementations§
impl Freeze for DigMessage
impl RefUnwindSafe for DigMessage
impl Send for DigMessage
impl Sync for DigMessage
impl Unpin for DigMessage
impl UnsafeUnpin for DigMessage
impl UnwindSafe for DigMessage
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.