pub struct CapabilityDiff {
pub node_id: u64,
pub base_version: u64,
pub new_version: u64,
pub ops: Vec<DiffOp>,
pub timestamp_ns: u64,
}Expand description
Capability diff message
Fields§
§node_id: u64Source node ID
base_version: u64Base version this diff applies to
new_version: u64New version after applying diff
ops: Vec<DiffOp>Operations to apply (in order)
timestamp_ns: u64Timestamp (nanoseconds since epoch)
Implementations§
Source§impl CapabilityDiff
impl CapabilityDiff
Sourcepub fn new(
node_id: u64,
base_version: u64,
new_version: u64,
ops: Vec<DiffOp>,
) -> CapabilityDiff
pub fn new( node_id: u64, base_version: u64, new_version: u64, ops: Vec<DiffOp>, ) -> CapabilityDiff
Create a new capability diff
Sourcepub fn estimated_size(&self) -> usize
pub fn estimated_size(&self) -> usize
Estimate total serialized size in bytes
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
👎Deprecated: use try_to_bytes — to_bytes swallows cap-violations as an empty Vec
pub fn to_bytes(&self) -> Vec<u8> ⓘ
use try_to_bytes — to_bytes swallows cap-violations as an empty Vec
Serialize to bytes (legacy — silent empty-on-failure path).
Returns Vec::new() on any encoding error or cap violation,
indistinguishable from a legitimate empty diff. A sender
that hit the cap silently transmits zero bytes; the receiver
drops the empty payload and the two sides diverge with no
diagnostic. New callers MUST use Self::try_to_bytes,
which surfaces the cap violation as a typed error.
Sourcepub fn try_to_bytes(&self) -> Result<Vec<u8>, DiffSizeError>
pub fn try_to_bytes(&self) -> Result<Vec<u8>, DiffSizeError>
Serialize to bytes with explicit size-cap enforcement.
Returns Err(DiffSizeError::TooManyOps) when ops.len()
exceeds MAX_DIFF_OPS, and Err(DiffSizeError::Encoded { … }) when the serialized form exceeds
MAX_DIFF_BYTES. Both checks MUST mirror what
Self::from_bytes enforces — otherwise the sender
would produce bytes the receiver silently discards.
Production senders building diffs from peer-supplied or
large-cardinality input MUST use this entry point.
Sourcepub fn from_bytes(data: &[u8]) -> Option<CapabilityDiff>
pub fn from_bytes(data: &[u8]) -> Option<CapabilityDiff>
Deserialize from bytes.
Rejects inputs over MAX_DIFF_BYTES before parsing, and
rejects diffs over MAX_DIFF_OPS after parsing. Both
failure modes return None — the existing
“malformed-or-too-large” outcome callers already handle.
Without these caps a peer-supplied 100 MB JSON would expand
into a Vec<DiffOp> of arbitrary length, and apply would
iterate every op (each currently a no-op for
SetField/UnsetField) — peer-controlled CPU/RAM burn
for no useful effect.
Trait Implementations§
Source§impl Clone for CapabilityDiff
impl Clone for CapabilityDiff
Source§fn clone(&self) -> CapabilityDiff
fn clone(&self) -> CapabilityDiff
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more