Struct Decode

Source
pub struct Decode<T: Message + FromStr = String> {
    pub input: InputPort<Bytes>,
    pub output: OutputPort<T>,
    pub encoding: Encoding,
}
Expand description

A block that decodes T messages from a byte stream.

§Block Diagram

block-beta
    columns 7
    Source space:2 Decode space:2 Sink
    Source-- "input" -->Decode
    Decode-- "output" -->Sink

    classDef block height:48px,padding:8px;
    classDef hidden visibility:none;
    class Decode block
    class Source hidden
    class Sink hidden

§Sequence Diagram

sequenceDiagram
    autonumber
    participant BlockA as Another block
    participant Decode.input as Decode.input port
    participant Decode as Decode block
    participant Decode.output as Decode.output port
    participant BlockB as Another block

    BlockA-->>Decode: Connect
    Decode-->>BlockB: Connect

    loop Decode process
        BlockA->>Decode: Message (Bytes)
        Decode->>Decode: Decode message
        Decode->>BlockB: Message
    end

    BlockA-->>Decode: Disconnect
    Decode-->>Decode.input: Close
    Decode-->>Decode.output: Close
    Decode-->>BlockB: Disconnect

§Examples

§Using the block in a system

System::build(|s| {
    let stdin = s.read_stdin();
    let message_decoder = s.decode_lines();
    let counter = s.count::<String>();
    let count_encoder = s.encode_lines();
    let stdout = s.write_stdout();
    s.connect(&stdin.output, &message_decoder.input);
    s.connect(&message_decoder.output, &counter.input);
    s.connect(&counter.count, &count_encoder.input);
    s.connect(&count_encoder.output, &stdout.input);
});

§Running the block via the CLI

$ protoflow execute Decode encoding=text
$ protoflow execute Decode encoding=protobuf

Fields§

§input: InputPort<Bytes>

The input byte stream.

§output: OutputPort<T>

The output message stream.

§encoding: Encoding

A configuration parameter for how to decode messages.

Implementations§

Source§

impl<T: Message + FromStr> Decode<T>

Source

pub fn new(input: InputPort<Bytes>, output: OutputPort<T>) -> Self

Source

pub fn with_params( input: InputPort<Bytes>, output: OutputPort<T>, encoding: Option<Encoding>, ) -> Self

Source§

impl<T: Message + FromStr + 'static> Decode<T>

Source

pub fn with_system(system: &System, encoding: Option<Encoding>) -> Self

Trait Implementations§

Source§

impl<T: Message + FromStr> Block for Decode<T>

Source§

fn execute(&mut self, _runtime: &dyn BlockRuntime) -> BlockResult

Executes this block’s computation.
Source§

fn prepare(&mut self, _runtime: &dyn BlockRuntime) -> Result<(), BlockError>

Prepares this block for execution. Read more
Source§

impl<T: Message + FromStr> BlockDescriptor for Decode<T>

Source§

fn inputs(&self) -> Vec<PortDescriptor>

A description of this block’s input ports.
Source§

fn outputs(&self) -> Vec<PortDescriptor>

A description of this block’s output ports.
Source§

fn parameters(&self) -> Vec<ParameterDescriptor>

A description of this block’s parameters.
Source§

fn ports(&self) -> Vec<PortDescriptor>

A description of this block’s I/O ports.
Source§

impl<T: Clone + Message + FromStr> Clone for Decode<T>

Source§

fn clone(&self) -> Decode<T>

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Message + FromStr> MaybeLabeled for Decode<T>

Source§

fn label(&self) -> Option<Cow<'_, str>>

Returns the human-readable label, if any, of the object.
Source§

fn is_labeled(&self) -> bool

Checks whether the object has a human-readable label.
Source§

impl<T: Message + FromStr> MaybeNamed for Decode<T>

Source§

fn name(&self) -> Option<Cow<'_, str>>

Returns the name, if any, of the object.
Source§

fn is_named(&self) -> bool

Checks whether the object has a name.
Source§

impl StdioSystem for Decode

Auto Trait Implementations§

§

impl<T> Freeze for Decode<T>

§

impl<T = String> !RefUnwindSafe for Decode<T>

§

impl<T> Send for Decode<T>

§

impl<T> Sync for Decode<T>

§

impl<T> Unpin for Decode<T>
where T: Unpin,

§

impl<T = String> !UnwindSafe for Decode<T>

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> AsBlock for T
where T: Block,

Source§

fn as_block(&self) -> &dyn Block

Source§

impl<T> AsBlockDescriptor for T
where T: BlockDescriptor,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V