pub struct Encode<T: Message + ToString = String> {
pub input: InputPort<T>,
pub output: OutputPort<Bytes>,
pub encoding: Encoding,
}Expand description
A block that encodes T messages to a byte stream.
§Block Diagram
block-beta
columns 7
Source space:2 Encode space:2 Sink
Source-- "input" -->Encode
Encode-- "output" -->Sink
classDef block height:48px,padding:8px;
classDef hidden visibility:none;
class Encode block
class Source hidden
class Sink hidden
§Sequence Diagram
sequenceDiagram
autonumber
participant BlockA as Another block
participant Encode.input as Encode.input port
participant Encode as Encode block
participant Encode.output as Encode.output port
participant BlockB as Another block
BlockA-->>Encode: Connect
Encode-->>BlockB: Connect
loop Encode process
BlockA->>Encode: Message
Encode->>Encode: Encode message
Encode->>BlockB: Message (Bytes)
end
BlockA-->>Encode: Disconnect
Encode-->>Encode.input: Close
Encode-->>Encode.output: Close
Encode-->>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 Encode encoding=text$ protoflow execute Encode encoding=protobufFields§
§input: InputPort<T>The input message stream.
output: OutputPort<Bytes>The output byte stream.
encoding: EncodingA configuration parameter for how to encode messages.
Implementations§
Trait Implementations§
Source§impl<T: Message + ToString> Block for Encode<T>
impl<T: Message + ToString> Block for Encode<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 + ToString> BlockDescriptor for Encode<T>
impl<T: Message + ToString> BlockDescriptor for Encode<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 Encode
impl StdioSystem for Encode
fn build_system(config: StdioConfig) -> Result<System, StdioError>
Auto Trait Implementations§
impl<T> Freeze for Encode<T>
impl<T = String> !RefUnwindSafe for Encode<T>
impl<T> Send for Encode<T>
impl<T> Sync for Encode<T>
impl<T> Unpin for Encode<T>where
T: Unpin,
impl<T = String> !UnwindSafe for Encode<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