Skip to main content

WireError

Enum WireError 

Source
pub enum WireError {
    Truncated {
        at: usize,
        needed: usize,
        available: usize,
    },
    ImpossibleLength {
        at: usize,
        claimed: usize,
        available: usize,
    },
    NotUtf8 {
        at: usize,
    },
    OutOfRange {
        at: usize,
        expected: String,
    },
    Discarded {
        at: usize,
        expected: String,
        found: String,
    },
    WrongFraming {
        at: usize,
        expected: String,
        found: String,
        fits: Option<&'static str>,
    },
}
Expand description

Why a read failed, or a write refused.

Every variant names what was expected and where. A reader that returned a zero for a truncated stream would hand the caller a value that was never sent; a writer that narrowed a value it cannot carry would send one nobody wrote. OutOfRange is the variant both use — at is the offset read from on the way in and the offset the value would have gone to on the way out.

Variants§

§

Truncated

The stream ended before the value did.

Fields

§at: usize

Where the read started.

§needed: usize

How many bytes it needed.

§available: usize

How many were left.

§

ImpossibleLength

A length field claims more than the stream holds.

Separate from Truncated: a length that cannot be true is a malformed stream, not a short one, and allocating for it is how a reader turns a bad message into an out-of-memory.

Fields

§at: usize

Where the length was read.

§claimed: usize

What it claimed.

§available: usize

How many bytes remain.

§

NotUtf8

A string held bytes that are not UTF-8.

Fields

§at: usize

Where the string started.

§

OutOfRange

A value outside what its type admits.

Fields

§at: usize

Where it was read.

§expected: String

What was expected.

§

Discarded

A value the receiving type cannot hold, under a position whose try_construct is DISCARD.

DDS-XTypes 1.3 §7.2.2.7 and §7.2.4.1: “the default behavior is to discard the O2 object to avoid misinterpretation.” §7.2.3 says the sample “can be safely ignored (filtered out) by the receiver”.

Kept apart from every other variant on purpose, and the distinction is measured. Cyclone’s path is the clearest witness: dds_stream_normalize fails inside ddsi_serdata_from_ser, which returns NULL, and delivery ends at remote_on_delivery_failure_fastpath — the sample never becomes a sample. A discarded sample is an absence, not an error. The stream is well formed and the next sample may well fit; every other variant here says the stream is wrong. The reflective column spells it ProbeError::Discarded, the C column ZDW_DISCARDED and the Python column Discarded.

Fields

§at: usize

Where the value that does not fit began.

§expected: String

What the receiving type can hold.

§found: String

What arrived.

§

WrongFraming

The stream is well formed and framed the way another implementation frames it, not the way this reader is configured.

Separate from Self::OutOfRange on purpose. A reader given the wrong dialect and a reader given a corrupt stream both stop, and only one of them is fixed by changing a flag. Telling a user “expected a four-byte parameter length” when the answer is --dialect fastdds costs an afternoon; naming the form the bytes do fit costs nothing.

Fields

§at: usize

Where the mismatch was found.

§expected: String

What the configured framing calls for.

§found: String

What the stream has instead.

§fits: Option<&'static str>

The setting whose other value the stream fits, when one does — Some("--pl-cdr1-headers short-true-length"). None when no configuration would have produced these bytes, which makes it a malformed stream after all.

Implementations§

Source§

impl WireError

Source

pub fn refused(at: usize, expected: &str) -> Self

A refusal raised from outside the runtime.

The runtime owns the wire and the generated code owns the type, and some refusals are the type’s: a member the stream says is absent where the generated field cannot hold an absence, a value that names no enumerator. runtime/c already has zdw_reader_refuse for exactly this; the Rust column had no way to say it and read on instead, which puts every following member at the wrong offset and reports success.

Source

pub const fn is_discarded(&self) -> bool

Whether this is the absence WireError::Discarded describes rather than a statement that the stream is malformed.

The one question a subscriber has to be able to ask: a discarded sample is dropped and the next one read, a malformed stream is reported. §7.2.4.1 against §7.2.3.

Trait Implementations§

Source§

impl Clone for WireError

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WireError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for WireError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for WireError

Source§

impl Error for WireError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl PartialEq for WireError

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for WireError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.