diff --git a/examples/csv_roundtrip.rs b/examples/csv_roundtrip.rs new file mode 100644 index 00000000..9d382c41 --- /dev/null +++ b/examples/csv_roundtrip.rs @@ -0,0 +1,26 @@ +#!/usr/bin/env rust-script +//! This is free and unencumbered software released into the public domain. +//! +//! ```cargo +//! [dependencies] +//! protoflow = "0.4.3" +//! ``` + +use protoflow::{blocks::*, BlockResult}; + +fn main() -> BlockResult { + System::run(|s| { + let csv_content = s.const_string("Name,Age,Score\nAlice,25,90\nBob,30,85\nCharlie,22,95"); + let line_encoder = s.encode_lines(); + let decoder = s.decode_csv(); + let encoder = s.encode_csv(); + let output_path = s.const_string("output.csv"); + let write_file = s.write_file(); + s.connect(&csv_content.output, &line_encoder.input); + s.connect(&line_encoder.output, &decoder.input); + s.connect(&decoder.header, &encoder.header); + s.connect(&decoder.rows, &encoder.rows); + s.connect(&output_path.output, &write_file.path); + s.connect(&encoder.output, &write_file.input); + }) +} diff --git a/examples/env_var_inspector.rs b/examples/env_var_inspector.rs new file mode 100755 index 00000000..dedffc48 --- /dev/null +++ b/examples/env_var_inspector.rs @@ -0,0 +1,23 @@ +#!/usr/bin/env rust-script +//! This is free and unencumbered software released into the public domain. +//! +//! ```cargo +//! [dependencies] +//! protoflow = "0.4.3" +//! ``` + +use protoflow::{blocks::*, BlockResult}; + +fn main() -> BlockResult { + System::run(|s| { + let name_param = s.const_string("PATH"); + let env_reader = s.read_env(); + let split_var = s.split_string(":"); + let line_encoder = s.encode_lines(); + let stdout = s.write_stdout(); + s.connect(&name_param.output, &env_reader.name); + s.connect(&env_reader.output, &split_var.input); + s.connect(&split_var.output, &line_encoder.input); + s.connect(&line_encoder.output, &stdout.input); + }) +} diff --git a/examples/hash_content.rs b/examples/hash_content.rs new file mode 100755 index 00000000..3e5d7daa --- /dev/null +++ b/examples/hash_content.rs @@ -0,0 +1,23 @@ +#!/usr/bin/env rust-script +//! This is free and unencumbered software released into the public domain. +//! +//! ```cargo +//! [dependencies] +//! protoflow = "0.4.3" +//! ``` + +use protoflow::{blocks::*, BlockResult}; + +fn main() -> BlockResult { + System::run(|s| { + let content = s.const_string("Hello, World!"); + let line_encoder = s.encode_lines(); + let hash_content = s.hash_sha2(); + let encode_hex = s.encode_hex(); + let stdout = s.write_stdout(); + s.connect(&content.output, &line_encoder.input); + s.connect(&line_encoder.output, &hash_content.input); + s.connect(&hash_content.hash, &encode_hex.input); + s.connect(&encode_hex.output, &stdout.input); + }) +} diff --git a/examples/json_sanitizer.rs b/examples/json_sanitizer.rs new file mode 100755 index 00000000..d65c8270 --- /dev/null +++ b/examples/json_sanitizer.rs @@ -0,0 +1,31 @@ +#!/usr/bin/env rust-script +//! This is free and unencumbered software released into the public domain. +//! +//! ```cargo +//! [dependencies] +//! protoflow = "0.4.3" +//! ``` + +use protoflow::{blocks::*, BlockResult}; + +fn main() -> BlockResult { + System::run(|s| { + let json_content = s.const_string( + r#"{ + "Name": "Alice", + "Age": 25, + "Score": 90 + }"#, + ); + let line_encoder = s.encode_lines(); + let decoder = s.decode_json(); + let encoder = s.encode_json(); + let sanitized_path = s.const_string("sanitized.json"); + let write_file = s.write_file(); + s.connect(&json_content.output, &line_encoder.input); + s.connect(&line_encoder.output, &decoder.input); + s.connect(&decoder.output, &encoder.input); + s.connect(&sanitized_path.output, &write_file.path); + s.connect(&encoder.output, &write_file.input); + }) +} diff --git a/examples/log_directories.rs b/examples/log_directories.rs new file mode 100644 index 00000000..789baba9 --- /dev/null +++ b/examples/log_directories.rs @@ -0,0 +1,26 @@ +#!/usr/bin/env rust-script +//! This is free and unencumbered software released into the public domain. +//! +//! ```cargo +//! [dependencies] +//! protoflow = "0.4.3" +//! ``` + +use protoflow::{blocks::*, BlockResult}; + +fn main() -> BlockResult { + System::run(|s| { + // The path to a directory + let dir_path = s.const_string("/"); + let dir_reader = s.read_dir(); + let concat_paths = s.concat_strings_by("\n"); + let line_encoder = s.encode_lines(); + let write_path = s.const_string("log_directories.txt"); + let write_file = s.write_file(); + s.connect(&dir_path.output, &dir_reader.path); + s.connect(&dir_reader.output, &concat_paths.input); + s.connect(&concat_paths.output, &line_encoder.input); + s.connect(&write_path.output, &write_file.path); + s.connect(&line_encoder.output, &write_file.input); + }) +} diff --git a/examples/write_and_read_file.rs b/examples/write_and_read_file.rs new file mode 100755 index 00000000..b5bc3e22 --- /dev/null +++ b/examples/write_and_read_file.rs @@ -0,0 +1,27 @@ +#!/usr/bin/env rust-script +//! This is free and unencumbered software released into the public domain. +//! +//! ```cargo +//! [dependencies] +//! protoflow = "0.4.3" +//! ``` + +use protoflow::{blocks::*, BlockResult}; + +fn main() -> BlockResult { + System::run(|s| { + let file_content = s.const_string("/home/user/documents\n/home/user/downloads\n/home/user/music\n/home/user/pictures\n/home/user/videos"); + let line_encoder = s.encode_lines(); + let content_path = s.const_string("content.txt"); + let write_file = s.write_file(); + s.connect(&file_content.output, &line_encoder.input); + s.connect(&content_path.output, &write_file.path); + s.connect(&line_encoder.output, &write_file.input); + + let file_path = s.const_string("content.txt"); + let reader = s.read_file(); + let stdout = s.write_stdout(); + s.connect(&file_path.output, &reader.path); + s.connect(&reader.output, &stdout.input); + }) +} diff --git a/lib/protoflow/examples/csv_processing/README.md b/lib/protoflow/examples/csv_processing/README.md new file mode 100644 index 00000000..a3aa8192 --- /dev/null +++ b/lib/protoflow/examples/csv_processing/README.md @@ -0,0 +1,29 @@ +# CSV Processing Example + +This is a simple five-block example program that starts with a constant string +containing CSV data, encodes it into a byte stream, decodes it back into +structured CSV data consisting of headers and rows, re-encodes that structured +data back into CSV format, and writes the result to standard output (stdout). + +Note that this program ensures the integrity of the CSV data during the decoding +and re-encoding process and demonstrates the handling of structured data in CSV format. + +## Block Diagram + +```mermaid +block-beta + columns 13 + Const space:2 Encode space:2 DecodeCSV space:2 EncodeCSV space:2 WriteStdout + Const-- "output → input" -->Encode + Encode-- "output → input" -->DecodeCSV + DecodeCSV-- "header,rows, → header,rows" -->EncodeCSV + EncodeCSV-- "output → input" -->WriteStdout + + classDef block height:48px,padding:8px; + classDef hidden visibility:none; + class Const block + class Encode block + class DecodeCSV block + class EncodeCSV block + class WriteStdout block +``` diff --git a/lib/protoflow/examples/csv_processing/main.rs b/lib/protoflow/examples/csv_processing/main.rs new file mode 100644 index 00000000..3545d8eb --- /dev/null +++ b/lib/protoflow/examples/csv_processing/main.rs @@ -0,0 +1,22 @@ +// This is free and unencumbered software released into the public domain. + +use protoflow::{blocks::*, BlockResult}; + +pub fn main() -> BlockResult { + System::run(|s| { + let csv = s.const_string("Name,Age,Score\nAlice,25,90\nBob,30,85\nCharlie,22,95"); + + let encoder = s.encode_lines(); + s.connect(&csv.output, &encoder.input); + + let csv_decoder = s.decode_csv(); + s.connect(&encoder.output, &csv_decoder.input); + + let csv_encoder = s.encode_csv(); + s.connect(&csv_decoder.header, &csv_encoder.header); + s.connect(&csv_decoder.rows, &csv_encoder.rows); + + let stdout = s.write_stdout(); + s.connect(&csv_encoder.output, &stdout.input); + }) +} diff --git a/lib/protoflow/examples/decode_hex/README.md b/lib/protoflow/examples/decode_hex/README.md new file mode 100644 index 00000000..06e8dce9 --- /dev/null +++ b/lib/protoflow/examples/decode_hex/README.md @@ -0,0 +1,27 @@ +# Hex Decode Example + +This is a simple four-block example program that starts with a constant string +containing hexadecimal-encoded data, encodes it into a byte stream, +decodes the hexadecimal back into raw bytes, and writes the decoded data to +standard output (stdout). + +Note that this program demonstrates how to handle hexadecimal input without +relying on external files or sources, making it fully self-contained. + +## Block Diagram + +```mermaid +block-beta + columns 10 + Const space:2 Encode space:2 DecodeHex space:2 WriteStdout + Const-- "output → input" -->Encode + Encode-- "output → input" -->DecodeHex + DecodeHex-- "output → input" -->WriteStdout + + classDef block height:48px,padding:8px; + classDef hidden visibility:none; + class Const block + class Encode block + class DecodeHex block + class WriteStdout block +``` diff --git a/lib/protoflow/examples/decode_hex/main.rs b/lib/protoflow/examples/decode_hex/main.rs new file mode 100644 index 00000000..1f4102ab --- /dev/null +++ b/lib/protoflow/examples/decode_hex/main.rs @@ -0,0 +1,18 @@ +// This is free and unencumbered software released into the public domain. + +use protoflow::{blocks::*, BlockResult}; + +pub fn main() -> BlockResult { + System::run(|s| { + let input_string = s.const_string("54686520717569636b2062726f776e20666f78206a756d7073206f76657220746865206c617a7920646f670a"); + + let encoder = s.encode_lines(); + s.connect(&input_string.output, &encoder.input); + + let hex_decoder = s.decode_hex(); + s.connect(&encoder.output, &hex_decoder.input); + + let stdout = s.write_stdout(); + s.connect(&hex_decoder.output, &stdout.input); + }) +} diff --git a/lib/protoflow/examples/delay_output/README.md b/lib/protoflow/examples/delay_output/README.md new file mode 100644 index 00000000..9cc84c18 --- /dev/null +++ b/lib/protoflow/examples/delay_output/README.md @@ -0,0 +1,29 @@ +# Delayed Line Output Example + +This is a simple five-block example program that starts with a constant string +containing multiple lines, splits the string into individual lines, +introduces a delay between processing each line, and writes the delayed lines +to standard output (stdout). + +Note that this program demonstrates how to control the timing of data processing, +making it suitable for simulating real-time output or throttling data streams + +## Block Diagram + +```mermaid +block-beta + columns 13 + Const space:2 SplitString space:2 Delay space:2 Encode space:2 WriteStdout + Const-- "output → input" -->SplitString + SplitString-- "output → input" -->Delay + Delay-- "output → input" -->Encode + Encode-- "output → input" -->WriteStdout + + classDef block height:48px,padding:8px; + classDef hidden visibility:none; + class Const block + class SplitString block + class Delay block + class Encode block + class WriteStdout block +``` diff --git a/lib/protoflow/examples/delay_output/main.rs b/lib/protoflow/examples/delay_output/main.rs new file mode 100644 index 00000000..4ae622fd --- /dev/null +++ b/lib/protoflow/examples/delay_output/main.rs @@ -0,0 +1,21 @@ +// This is free and unencumbered software released into the public domain. + +use protoflow::{blocks::*, BlockResult}; + +pub fn main() -> BlockResult { + System::run(|s| { + let input_string = s.const_string("Line 1\nLine 2\nLine 3\nLine 4"); + + let split_string = s.split_string("\n"); + s.connect(&input_string.output, &split_string.input); + + let delay = s.delay(); + s.connect(&split_string.output, &delay.input); + + let encoder = s.encode_lines(); + s.connect(&delay.output, &encoder.input); + + let stdout = s.write_stdout(); + s.connect(&encoder.output, &stdout.input); + }) +} diff --git a/lib/protoflow/examples/encode_hex/README.md b/lib/protoflow/examples/encode_hex/README.md new file mode 100644 index 00000000..531d2fd2 --- /dev/null +++ b/lib/protoflow/examples/encode_hex/README.md @@ -0,0 +1,27 @@ +# Hex Encode Example + +This is a simple four-block example program that starts with a constant string, +encodes it into a byte stream, converts the bytes into hexadecimal format, +and writes the hexadecimal-encoded output to standard output (stdout). + +Note that this program demonstrates how to transform human-readable text into +its hexadecimal representation, which can be useful for encoding data for secure +transmission or storage. + +## Block Diagram + +```mermaid +block-beta + columns 10 + Const space:2 Encode space:2 EncodeHex space:2 WriteStdout + Const-- "output → input" -->Encode + Encode-- "output → input" -->EncodeHex + EncodeHex-- "output → input" -->WriteStdout + + classDef block height:48px,padding:8px; + classDef hidden visibility:none; + class Const block + class Encode block + class EncodeHex block + class WriteStdout block +``` diff --git a/lib/protoflow/examples/encode_hex/main.rs b/lib/protoflow/examples/encode_hex/main.rs new file mode 100644 index 00000000..dfd78c79 --- /dev/null +++ b/lib/protoflow/examples/encode_hex/main.rs @@ -0,0 +1,18 @@ +// This is free and unencumbered software released into the public domain. + +use protoflow::{blocks::*, BlockResult}; + +pub fn main() -> BlockResult { + System::run(|s| { + let input_string = s.const_string("The quick brown fox jumps over the lazy dog"); + + let encoder = s.encode_lines(); + s.connect(&input_string.output, &encoder.input); + + let hex_encoder = s.encode_hex(); + s.connect(&encoder.output, &hex_encoder.input); + + let stdout = s.write_stdout(); + s.connect(&hex_encoder.output, &stdout.input); + }) +} diff --git a/lib/protoflow/examples/json_processing/README.md b/lib/protoflow/examples/json_processing/README.md new file mode 100644 index 00000000..18d03740 --- /dev/null +++ b/lib/protoflow/examples/json_processing/README.md @@ -0,0 +1,30 @@ +# JSON Processing Example + +This is a simple five-block example program that starts with a constant string +containing JSON data, encodes it into a byte stream, decodes it back into +structured JSON data, re-encodes that structured data into JSON format, +and writes the re-encoded JSON data to standard output (stdout). + +Note that this program demonstrates the complete processing cycle of JSON data, +ensuring that the data is parsed and re-encoded while preserving its original +structure. + +## Block Diagram + +```mermaid +block-beta + columns 13 + Const space:2 Encode space:2 DecodeJSON space:2 EncodeJSON space:2 WriteStdout + Const-- "output → input" -->Encode + Encode-- "output → input" -->DecodeJSON + DecodeJSON-- "output, → input" -->EncodeJSON + EncodeJSON-- "output → input" -->WriteStdout + + classDef block height:48px,padding:8px; + classDef hidden visibility:none; + class Const block + class Encode block + class DecodeJSON block + class EncodeJSON block + class WriteStdout block +``` diff --git a/lib/protoflow/examples/json_processing/main.rs b/lib/protoflow/examples/json_processing/main.rs new file mode 100644 index 00000000..9749ea6e --- /dev/null +++ b/lib/protoflow/examples/json_processing/main.rs @@ -0,0 +1,21 @@ +// This is free and unencumbered software released into the public domain. + +use protoflow::{blocks::*, BlockResult}; + +pub fn main() -> BlockResult { + System::run(|s| { + let json = s.const_string(r#"{"Name": "Alice","Age": 25,"Score": 90}"#); + + let line_encoder = s.encode_lines(); + s.connect(&json.output, &line_encoder.input); + + let decoder = s.decode_json(); + s.connect(&line_encoder.output, &decoder.input); + + let encoder = s.encode_json(); + s.connect(&decoder.output, &encoder.input); + + let stdout = s.write_stdout(); + s.connect(&encoder.output, &stdout.input); + }) +} diff --git a/lib/protoflow/examples/process_env_var/README.md b/lib/protoflow/examples/process_env_var/README.md new file mode 100644 index 00000000..b7ee6f22 --- /dev/null +++ b/lib/protoflow/examples/process_env_var/README.md @@ -0,0 +1,32 @@ +# Environment Variable Processor Example + +This is a simple five-block example program that starts by reading the PATH +environment variable, splits its value into individual components based on +the : delimiter, transforms the components into a newline-separated list, +and writes the resulting list to standard output (stdout). + +Note that this program demonstrates how to process and format environment +variable values, making it suitable for scenarios where structured output +of environment variables is required. + +## Block Diagram + +```mermaid +block-beta + columns 16 + Const space:2 ReadEnv space:2 SplitString space:2 ConcatStrings space:2 Encode space:2 WriteStdout + Const-- "output → name" -->ReadEnv + ReadEnv-- "output → input" -->SplitString + SplitString-- "output, → input" -->ConcatStrings + ConcatStrings-- "output → input" -->Encode + Encode-- "output → input" -->WriteStdout + + classDef block height:48px,padding:8px; + classDef hidden visibility:none; + class Const block + class ReadEnv block + class SplitString block + class ConcatStrings block + class Encode block + class WriteStdout block +``` diff --git a/lib/protoflow/examples/process_env_var/main.rs b/lib/protoflow/examples/process_env_var/main.rs new file mode 100644 index 00000000..bc6a0254 --- /dev/null +++ b/lib/protoflow/examples/process_env_var/main.rs @@ -0,0 +1,20 @@ +// This is free and unencumbered software released into the public domain. + +use protoflow::{blocks::*, BlockResult}; + +pub fn main() -> BlockResult { + System::run(|s| { + let env_var_name = s.const_string("PATH"); + let read_env = s.read_env(); + s.connect(&env_var_name.output, &read_env.name); + + let split_env = s.split_string(":"); + s.connect(&read_env.output, &split_env.input); + + let line_encoder = s.encode_lines(); + s.connect(&split_env.output, &line_encoder.input); + + let write_stdout = s.write_stdout(); + s.connect(&line_encoder.output, &write_stdout.input); + }) +} diff --git a/lib/protoflow/examples/read_file/README.md b/lib/protoflow/examples/read_file/README.md new file mode 100644 index 00000000..f69f0004 --- /dev/null +++ b/lib/protoflow/examples/read_file/README.md @@ -0,0 +1,36 @@ +# Read File Example + +This is a simple seven-block example program that begins with a constant string +containing multiple lines of text, writes the content to a file, reads the file +back into the system, and writes the file's content to standard output (stdout). + +Note that this program is fully self-contained, creating and processing the file +entirely within the flow, making it suitable for demonstrating file handling +in a standalone scenario. + +## Block Diagram + +```mermaid +block-beta + columns 7 + space:3 Const_wpath space:3 + space:6 WriteFile + Const_content space:2 Encode space:3 + space:7 + Const_rpath space:2 ReadFile space:2 WriteStdout + Const_wpath-- "output → path" -->WriteFile + Const_content-- "output → input" -->Encode + Encode-- "output → input" -->WriteFile + Const_rpath-- "output → path" -->ReadFile + ReadFile-- "output → input" -->WriteStdout + + classDef block height:48px,padding:8px; + classDef hidden visibility:none; + class Const_wpath block + class Const_content block + class Const_rpath block + class Encode block + class WriteFile block + class ReadFile block + class WriteStdout block +``` diff --git a/lib/protoflow/examples/read_file/main.rs b/lib/protoflow/examples/read_file/main.rs new file mode 100644 index 00000000..87f6fe6b --- /dev/null +++ b/lib/protoflow/examples/read_file/main.rs @@ -0,0 +1,23 @@ +// This is free and unencumbered software released into the public domain. + +use protoflow::{blocks::*, BlockResult}; + +pub fn main() -> BlockResult { + System::run(|s| { + let initial_content = s.const_string("This is line 1\nThis is line 2\nThis is line 3"); + let encoder = s.encode_lines(); + s.connect(&initial_content.output, &encoder.input); + + let write_file = s.write_file(); + let write_path = s.const_string("self_contained_file.txt"); + s.connect(&encoder.output, &write_file.input); + s.connect(&write_path.output, &write_file.path); + + let read_path = s.const_string("self_contained_file.txt"); + let read_file = s.read_file(); + s.connect(&read_path.output, &read_file.path); + + let stdout = s.write_stdout(); + s.connect(&read_file.output, &stdout.input); + }) +} diff --git a/lib/protoflow/examples/write_file/README.md b/lib/protoflow/examples/write_file/README.md new file mode 100644 index 00000000..242c0641 --- /dev/null +++ b/lib/protoflow/examples/write_file/README.md @@ -0,0 +1,25 @@ +# Write File Example + +This is a simple three-block example program that reads input from standard input +(stdin) and writes the content directly to a file (`output.txt`). + +Note that this program demonstrates how to capture user input or piped data +and store it persistently in a file. + +## Block Diagram + +```mermaid +block-beta + columns 4 + Const space:3 + space:3 WriteFile + ReadStdin + ReadStdin-- "output → input" -->WriteFile + Const-- "output → path" -->WriteFile + + classDef block height:48px,padding:8px; + classDef hidden visibility:none; + class ReadStdin block + class Const block + class WriteFile block +``` diff --git a/lib/protoflow/examples/write_file/main.rs b/lib/protoflow/examples/write_file/main.rs new file mode 100644 index 00000000..54da2f05 --- /dev/null +++ b/lib/protoflow/examples/write_file/main.rs @@ -0,0 +1,13 @@ +// This is free and unencumbered software released into the public domain. + +use protoflow::{blocks::*, BlockResult}; + +pub fn main() -> BlockResult { + System::run(|s| { + let stdin = s.read_stdin(); + let file_path = s.const_string("output.txt"); + let write_file = s.write_file(); + s.connect(&stdin.output, &write_file.input); + s.connect(&file_path.output, &write_file.path); + }) +}