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=protobufFields§
§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§fn parameters(&self) -> Vec<ParameterDescriptor>
fn parameters(&self) -> Vec<ParameterDescriptor>
A description of this block’s parameters.
Source§fn ports(&self) -> Vec<PortDescriptor>
fn ports(&self) -> Vec<PortDescriptor>
A description of this block’s I/O ports.
Source§impl StdioSystem for Decode
impl StdioSystem for Decode
fn build_system(config: StdioConfig) -> Result<System, StdioError>
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> AsBlockDescriptor for Twhere
T: BlockDescriptor,
impl<T> AsBlockDescriptor for Twhere
T: BlockDescriptor,
fn as_block_descriptor(&self) -> &dyn BlockDescriptor
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