Struct protoflow_blocks::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
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: EncodingA configuration parameter for how to decode messages.
Implementations§
Trait Implementations§
source§impl<T: Message + FromStr> Block for Decode<T>
impl<T: Message + FromStr> Block for Decode<T>
source§fn execute(&mut self, _runtime: &dyn BlockRuntime) -> BlockResult
fn execute(&mut self, _runtime: &dyn BlockRuntime) -> BlockResult
Executes this block’s computation.
source§fn prepare(&mut self, _runtime: &dyn BlockRuntime) -> Result<(), BlockError>
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>
impl<T: Message + FromStr> BlockDescriptor for Decode<T>
source§fn inputs(&self) -> Vec<PortDescriptor>
fn inputs(&self) -> Vec<PortDescriptor>
A description of this block’s input ports.
source§fn outputs(&self) -> Vec<PortDescriptor>
fn outputs(&self) -> Vec<PortDescriptor>
A description of this block’s output ports.
source§impl<T: Message + FromStr> Definition for Decode<T>
impl<T: Message + FromStr> Definition for Decode<T>
fn is_variation(&self) -> bool
source§impl<T: Message + FromStr> Element for Decode<T>
impl<T: Message + FromStr> Element for Decode<T>
source§fn short_name(&self) -> Option<&str>
fn short_name(&self) -> Option<&str>
The short name of the element, if any.
source§fn is_library_element(&self) -> bool
fn is_library_element(&self) -> bool
Whether this
Element is contained in the ownership tree of
a library model.source§fn owning_namespace(&self) -> Option<&dyn Namespace>
fn owning_namespace(&self) -> Option<&dyn Namespace>
source§fn owning_relationship(&self) -> Option<&dyn Relationship>
fn owning_relationship(&self) -> Option<&dyn Relationship>
fn qualified_name(&self) -> Option<QualifiedName>
source§impl<T: Message + FromStr> OccurrenceDefinition for Decode<T>
impl<T: Message + FromStr> OccurrenceDefinition for Decode<T>
fn is_individual(&self) -> bool
source§impl StdioSystem for Decode
impl StdioSystem for Decode
fn build_system(_config: StdioConfig) -> Result<System, StdioError>
source§impl<T: Message + FromStr> Type for Decode<T>
impl<T: Message + FromStr> Type for Decode<T>
fn is_abstract(&self) -> bool
fn is_sufficient(&self) -> bool
fn is_conjugated(&self) -> bool
fn specializes(&self, _supertype: &Self) -> bool
impl<T: Message + FromStr> BlockDefinition for Decode<T>
impl<T: Message + FromStr> Class for Decode<T>
impl<T: Message + FromStr> Classifier for Decode<T>
impl<T: Message + FromStr> ItemDefinition for Decode<T>
impl<T: Message + FromStr> PartDefinition for Decode<T>
impl<T: Message + FromStr> Structure for Decode<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)