Enum flipdot_core::Message[][src]

#[non_exhaustive]pub enum Message<'a> {
    SendData(OffsetData<'a>),
    DataChunksSent(ChunkCount),
    Hello(Address),
    QueryState(Address),
    ReportState(AddressState),
    RequestOperation(AddressOperation),
    AckOperation(AddressOperation),
    PixelsComplete(Address),
    Goodbye(Address),
    Unknown(Frame<'a>),
}

High-level representation of a sign bus communication message.

Ascribes meaning to a Frame and is freely convertible to and from one (with Unknown to allow round-tripping unknown message types). This is the primary way that messages are represented in flipdot.

Examples

use flipdot_core::{Address, Message, SignBus, State};
use flipdot_testing::{VirtualSign, VirtualSignBus};

let mut bus = VirtualSignBus::new(vec![VirtualSign::new(Address(3))]);

// Message is the currency used to send and receive messages on a bus:
let response = bus.process_message(Message::QueryState(Address(3)))?;
assert_eq!(Some(Message::ReportState(Address(3), State::Unconfigured)), response);

Variants (Non-exhaustive)

Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
SendData(OffsetData<'a>)

Send a chunk of data, with the first member indicating the offset.

E.g. when sending 32 bytes of data in two 16-byte chunks, the first message would have offset 0 and the second would have offset 16. No response is expected.

DataChunksSent(ChunkCount)

Notifies that we are done sending data, and specifies how many chunks were sent.

No response is expected.

Hello(Address)

Initially discovers the sign with the given address on the bus.

A ReportState message with the sign’s current state is expected.

QueryState(Address)

Queries the sign with the given address for its current state.

A ReportState message with the sign’s current state is expected.

ReportState(AddressState)

Indicates the state of the sign with the given address.

Sent by the sign in response to a Hello orQueryState message.

RequestOperation(AddressOperation)

Requests that the sign with the given address perform an operation.

An AckOperation response is expected.

AckOperation(AddressOperation)

Sent by the sign with the given address indicating that it will perform the given operation.

PixelsComplete(Address)

Indicates that the pixel data for the sign with the given address has been fully transferred.

This indicates that the sign should load it into memory in preparation to show. No response is expected.

Goodbye(Address)

Notifies the sign with the given address to blank its display and shut down.

The sign will not be usable for 30 seconds after receiving this message. Generally optional as disconnecting switched power from the sign should have the same effect. No response is expected.

Unknown(Frame<'a>)

Wraps a Frame that does not correspond to any known message.

Trait Implementations

impl<'a> Clone for Message<'a>[src]

impl<'a> Debug for Message<'a>[src]

impl Display for Message<'_>[src]

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

Provides a human-readable view of the message.

This is useful, for example, when monitoring the traffic on a bus.

impl<'a> Eq for Message<'a>[src]

impl<'a> From<Frame<'a>> for Message<'a>[src]

fn from(frame: Frame<'a>) -> Self[src]

Converts a Frame into a Message.

This cannot fail as all valid Frames are representable as Messages (though perhaps Unknown). The input Frame is consumed to allow efficiently reusing its data where possible.

Examples

let frame = Frame::new(Address(0x12), MsgType(4), Data::try_new(vec![0x07])?);
let message = Message::from(frame);
assert_eq!(Message::ReportState(Address(0x12), State::ConfigReceived), message);

impl<'a> From<Message<'a>> for Frame<'a>[src]

fn from(message: Message<'a>) -> Self[src]

Converts a Message into a Frame.

This cannot fail as all Messages can be represented as Frames. The input Message is consumed to allow efficiently reusing its data where possible.

Examples

let message = Message::ReportState(Address(0xFF), State::ConfigReceived);
let frame = Frame::from(message);
assert_eq!(Frame::new(Address(0xFF), MsgType(4), Data::try_new(vec![0x07])?), frame);

impl<'a> Hash for Message<'a>[src]

impl<'a> PartialEq<Message<'a>> for Message<'a>[src]

impl<'a> StructuralEq for Message<'a>[src]

impl<'a> StructuralPartialEq for Message<'a>[src]

Auto Trait Implementations

impl<'a> RefUnwindSafe for Message<'a>

impl<'a> Send for Message<'a>

impl<'a> Sync for Message<'a>

impl<'a> Unpin for Message<'a>

impl<'a> UnwindSafe for Message<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.