Skip to main content

Message

Enum Message 

Source
pub enum Message {
    General {
        msgid: u64,
        data: Option<Vec<u8>>,
    },
    Configuration {
        msgid: u64,
        gateway: String,
        data: Option<Vec<u8>>,
    },
    Control {
        msgid: u64,
        srcid: u64,
        action: String,
        target: String,
        data: Option<Vec<u8>>,
    },
    Ack {
        msgid: u64,
        ack: u64,
    },
    Error {
        msgid: u64,
        reason: String,
    },
    StdOut {
        msgid: u64,
        srcid: u64,
        nodes: String,
        data: Option<Vec<u8>>,
    },
    StdErr {
        msgid: u64,
        srcid: u64,
        nodes: String,
        data: Option<Vec<u8>>,
    },
    Retcode {
        msgid: u64,
        srcid: u64,
        retcode: i32,
        nodes: String,
    },
    Timeout {
        msgid: u64,
        srcid: u64,
        nodes: String,
    },
    Routing {
        msgid: u64,
        srcid: u64,
        event: String,
        gateway: String,
        targets: String,
    },
    Start {
        msgid: u64,
    },
    End {
        msgid: u64,
    },
}
Expand description

A communication message in the propagation tree protocol.

Messages are tagged unions representing the different message types exchanged between ClusterShell nodes. Each variant carries the fields specific to that message type.

Variants§

§

General

Generic base message.

Fields

§msgid: u64
§data: Option<Vec<u8>>
§

Configuration

Configuration propagation container (ident = “CFG”). Has payload. Carries serialized topology.

Fields

§msgid: u64
§gateway: String
§data: Option<Vec<u8>>
§

Control

Action request routed through the tree (ident = “CTL”). Has payload. Carries serialized command data.

Fields

§msgid: u64
§srcid: u64
§action: String
§target: String
§data: Option<Vec<u8>>
§

Ack

Acknowledgement message (ident = “ACK”).

Fields

§msgid: u64
§ack: u64
§

Error

Error message (ident = “ERR”).

Fields

§msgid: u64
§reason: String
§

StdOut

Standard output container (ident = “OUT”). Has payload. Carries encoded output data.

Fields

§msgid: u64
§srcid: u64
§nodes: String
§data: Option<Vec<u8>>
§

StdErr

Standard error container (ident = “SER”). Has payload. Carries encoded stderr data.

Fields

§msgid: u64
§srcid: u64
§nodes: String
§data: Option<Vec<u8>>
§

Retcode

Return code container (ident = “RET”).

Fields

§msgid: u64
§srcid: u64
§retcode: i32
§nodes: String
§

Timeout

Timeout notification (ident = “TIM”).

Fields

§msgid: u64
§srcid: u64
§nodes: String
§

Routing

Routing notification (ident = “RTR”).

Fields

§msgid: u64
§srcid: u64
§event: String
§gateway: String
§targets: String
§

Start

Start of channel communication (ident = “CHA”).

Fields

§msgid: u64
§

End

End of channel communication (ident = “END”).

Fields

§msgid: u64

Implementations§

Source§

impl Message

Source

pub fn general() -> Self

Create a new General message.

Source

pub fn configuration(gateway: &str) -> Self

Create a new Configuration message.

Source

pub fn control(srcid: u64) -> Self

Create a new Control message.

Source

pub fn ack(ackid: u64) -> Self

Create a new Ack message.

Source

pub fn error(reason: &str) -> Self

Create a new Error message.

Source

pub fn stdout(nodes: &str, srcid: u64) -> Self

Create a new StdOut message.

Source

pub fn stderr(nodes: &str, srcid: u64) -> Self

Create a new StdErr message.

Source

pub fn retcode(nodes: &str, retcode: i32, srcid: u64) -> Self

Create a new Retcode message.

Source

pub fn timeout(nodes: &str, srcid: u64) -> Self

Create a new Timeout message.

Source

pub fn routing(event: &str, gateway: &str, targets: &str, srcid: u64) -> Self

Create a new Routing message.

Source

pub fn start() -> Self

Create a Start message.

Source

pub fn end() -> Self

Create an End message.

Source

pub fn ident(&self) -> &str

Get the message type identifier string.

Source

pub fn msgid(&self) -> u64

Get the message ID.

Source

pub fn has_payload(&self) -> bool

Whether this message type carries a payload.

Source

pub fn data(&self) -> Option<&[u8]>

Get a reference to the payload data, if any.

Source

pub fn set_data(&mut self, payload: Vec<u8>)

Set the payload data (raw bytes, will be base64-encoded on serialization).

Source

pub fn data_encode(&mut self, raw: &[u8])

Encode arbitrary bytes as base64 and store as payload.

Source

pub fn data_decode(&self) -> Result<Vec<u8>, MessageProcessingError>

Decode the base64 payload back to raw bytes.

Source

pub fn data_update(&mut self, raw: &[u8]) -> Result<(), MessageProcessingError>

Append data during incremental XML parsing.

Source

pub fn srcid(&self) -> Option<u64>

Get the srcid for routed messages, None for non-routed.

Source

pub fn nodes(&self) -> Option<&str>

Get the nodes field if present.

Source

pub fn xml(&self) -> Vec<u8> ⓘ

Serialize this message to XML bytes.

Produces output like: <message type="CFG" msgid="0" gateway="gw1">base64payload</message>

Source

pub fn from_attrs( attrs: &HashMap<String, String>, ) -> Result<Message, MessageProcessingError>

Build a message from parsed XML attributes.

The message type is selected based on the “type” attribute, and all other attributes are read according to the variant’s schema.

Trait Implementations§

Source§

impl Clone for Message

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 Message

Source§

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

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

impl Display for Message

Source§

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

Formats the value using the given formatter. Read more

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.