Struct protoflow_blocks::Encode
source · 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
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=protobuf
Fields§
§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§impl<T: Message + ToString> Definition for Encode<T>
impl<T: Message + ToString> Definition for Encode<T>
fn is_variation(&self) -> bool
source§impl<T: Message + ToString> Element for Encode<T>
impl<T: Message + ToString> Element for Encode<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 + ToString> OccurrenceDefinition for Encode<T>
impl<T: Message + ToString> OccurrenceDefinition for Encode<T>
fn is_individual(&self) -> bool
source§impl StdioSystem for Encode
impl StdioSystem for Encode
fn build_system(_config: StdioConfig) -> Result<System, StdioError>
source§impl<T: Message + ToString> Type for Encode<T>
impl<T: Message + ToString> Type for Encode<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 + ToString> BlockDefinition for Encode<T>
impl<T: Message + ToString> Class for Encode<T>
impl<T: Message + ToString> Classifier for Encode<T>
impl<T: Message + ToString> ItemDefinition for Encode<T>
impl<T: Message + ToString> PartDefinition for Encode<T>
impl<T: Message + ToString> Structure for Encode<T>
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> 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)