6 个版本

新版本 0.2.1 2024 年 8 月 24 日
0.2.0 2024 年 8 月 21 日
0.1.1 2024 年 8 月 20 日
0.0.13 2024 年 8 月 14 日

#714并发

Download history 248/week @ 2024-08-09 458/week @ 2024-08-16

每月 706 次下载
2 个 crate 中使用 (通过 protoflow)

Unlicense

90KB
1.5K SLoC

Protoflow

License Compatibility Package

"万物皆流,无物常驻" — 柏拉图

🚧 我们在公众面前构建。目前正在全力建设中。

🛠️ 前提条件

⬇️ 安装

通过 Homebrew 安装

brew tap AsimovPlatform/tap
brew install protoflow --HEAD

通过 Cargo 安装

cargo install protoflow

👉 示例

Rust 示例

有关 Rust 示例,请参阅 examples 目录。一个好的起点是 echo_linescount_lines 示例。

📚 参考

术语表

  • 系统: 一组相互连接的块。系统是 Protoflow 程序中的顶级实体。

  • : 封装的消息处理系统组件。块是系统中的自主计算单元。

  • 端口: 块上用于发送或接收消息的命名连接点。端口是块之间通信的唯一接口。

  • 消息: 在系统中的块之间流动的数据单元。消息是块处理的协议缓冲区数据包。

描述
缓冲区 存储它接收到的所有消息。
常量 发送一个常数。
计数 计算它接收到的消息数量,同时可选地通过它们。
解码 从字节流解码消息。
延迟 在固定或随机延迟期间通过消息。
丢弃 丢弃它接收到的所有消息。
编码 将消息编码到字节流。
编码十六进制 将字节流编码为十六进制形式。
哈希 计算字节流的加密哈希。
随机 生成并发送随机值。
读取目录 从文件系统目录读取文件名。
读取环境变量 读取环境变量的值。
读取文件 从文件内容中读取字节。
ReadStdin 从标准输入(即stdin)读取字节。
WriteFile 将字节写入或追加到文件内容中。
WriteStderr 将字节写入标准错误(即stderr)。
WriteStdout 将字节写入标准输出(即stdout)。

缓冲区

一个简单地存储它接收到的所有消息的块。

block-beta
    columns 4
    Source space:2 Buffer
    Source-- "input" -->Buffer

    classDef block height:48px,padding:8px;
    classDef hidden visibility:none;
    class Buffer block
    class Source hidden
protoflow execute Buffer

常量

一个用于发送一个常数值的块。

block-beta
    columns 4
    Const space:2 Sink
    Const-- "output" -->Sink

    classDef block height:48px,padding:8px;
    classDef hidden visibility:none;
    class Const block
    class Sink hidden
protoflow execute Const value=Hello

计数

一个计数它接收到的消息数量的块,同时可选地通过它们。

block-beta
    columns 7
    Source space:2 Count space:2 Sink
    space:7
    space:7
    space:3 Result space:3
    Source-- "input" -->Count
    Count-- "output" -->Sink
    Count-- "count" -->Result

    classDef block height:48px,padding:8px;
    classDef hidden visibility:none;
    class Count block
    class Source hidden
    class Sink hidden
    class Result hidden
protoflow execute Count

解码

一个从字节流中解码 T 消息的块。

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
protoflow execute Decode encoding=text

延迟

一个在固定或随机延迟期间延迟消息并通过它们的块。

block-beta
    columns 7
    Source space:2 Delay space:2 Sink
    Source-- "input" -->Delay
    Delay-- "output" -->Sink

    classDef block height:48px,padding:8px;
    classDef hidden visibility:none;
    class Delay block
    class Source hidden
    class Sink hidden
protoflow execute Delay fixed=2

丢弃

一个简单地丢弃它接收到的所有消息的块。

block-beta
    columns 4
    Source space:2 Drop
    Source-- "input" -->Drop

    classDef block height:48px,padding:8px;
    classDef hidden visibility:none;
    class Drop block
    class Source hidden
protoflow execute Drop

编码

一个将 T 消息编码到字节流的块。

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
protoflow execute Encode encoding=text
protoflow execute Encode encoding=protobuf

编码十六进制

一个将字节流编码成十六进制形式的块。

block-beta
    columns 7
    Source space:2 EncodeHex space:2 Sink
    Source-- "input" -->EncodeHex
    EncodeHex-- "output" -->Sink

    classDef block height:48px,padding:8px;
    classDef hidden visibility:none;
    class EncodeHex block
    class Source hidden
    class Sink hidden
protoflow execute EncodeHex

哈希

一个计算字节流的加密散列的块,同时可选地通过它。

block-beta
    columns 7
    Source space:2 Hash space:2 Sink
    space:7
    space:7
    space:3 Result space:3
    Source-- "input" -->Hash
    Hash-- "output" -->Sink
    Hash-- "hash" -->Result

    classDef block height:48px,padding:8px;
    classDef hidden visibility:none;
    class Hash block
    class Source hidden
    class Sink hidden
    class Result hidden
protoflow execute Hash algorithm=blake3

随机

一个用于生成和发送随机值的块。

block-beta
    columns 4
    Random space:2 Sink
    Random-- "output" -->Sink

    classDef block height:48px,padding:8px;
    classDef hidden visibility:none;
    class Random block
    class Sink hidden
protoflow execute Random seed=42

读取目录

一个从文件系统目录中读取文件名的块。

block-beta
    columns 4
    Config space:3
    space:4
    space:4
    ReadDir space:2 Sink
    Config-- "path" -->ReadDir
    ReadDir-- "output" -->Sink

    classDef block height:48px,padding:8px;
    classDef hidden visibility:none;
    class ReadDir block
    class Config hidden
    class Sink hidden
protoflow execute ReadDir path=/tmp

读取环境变量

一个读取环境变量值的块。

block-beta
    columns 4
    Config space:3
    space:4
    space:4
    ReadEnv space:2 Sink
    Config-- "name" -->ReadEnv
    ReadEnv-- "output" -->Sink

    classDef block height:48px,padding:8px;
    classDef hidden visibility:none;
    class ReadEnv block
    class Config hidden
    class Sink hidden
protoflow execute ReadEnv name=TERM

读取文件

一个从文件内容中读取字节的块。

block-beta
    columns 4
    Config space:3
    space:4
    space:4
    ReadFile space:2 Sink
    Config-- "path" -->ReadFile
    ReadFile-- "output" -->Sink

    classDef block height:48px,padding:8px;
    classDef hidden visibility:none;
    class ReadFile block
    class Config hidden
    class Sink hidden
protoflow execute ReadFile path=/tmp/file.txt

ReadStdin

一个从标准输入(即stdin)读取字节的块。

block-beta
    columns 4
    ReadStdin space:2 Sink
    ReadStdin-- "output" -->Sink

    classDef block height:48px,padding:8px;
    classDef hidden visibility:none;
    class ReadStdin block
    class Sink hidden
protoflow execute ReadStdin < input.txt

WriteFile

一个将字节写入或追加到文件内容的块。

block-beta
    columns 4
    space:3 Config
    space:4
    space:4
    Source space:2 WriteFile
    Config-- "path" -->WriteFile
    Source-- "input" -->WriteFile

    classDef block height:48px,padding:8px;
    classDef hidden visibility:none;
    class WriteFile block
    class Config hidden
    class Source hidden
protoflow execute WriteFile path=/tmp/file.txt

WriteStderr

一个将字节写入标准错误(即stderr)的块。

block-beta
    columns 4
    Source space:2 WriteStderr
    Source-- "input" -->WriteStderr

    classDef block height:48px,padding:8px;
    classDef hidden visibility:none;
    class WriteStderr block
    class Source hidden
protoflow execute WriteStderr < input.txt 2> output.txt

WriteStdout

一个将字节写入标准输出(即stdout)的块。

block-beta
    columns 4
    Source space:2 WriteStdout
    Source-- "input" -->WriteStdout

    classDef block height:48px,padding:8px;
    classDef hidden visibility:none;
    class WriteStdout block
    class Source hidden
protoflow execute WriteStdout < input.txt > output.txt

👨‍💻 开发

git clone https://github.com/AsimovPlatform/protoflow.git

Share on Twitter Share on Reddit Share on Hacker News Share on Facebook

依赖关系

~2.8–9MB
~79K SLoC