Skip to content

Commit

Permalink
Organize docs about messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
temeddix committed Jun 17, 2024
1 parent 297f40c commit 412adfb
Showing 1 changed file with 53 additions and 42 deletions.
95 changes: 53 additions & 42 deletions documentation/docs/messaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,86 +2,97 @@

There are 2 types of special comments that you can mark messages with.

## 📭 Dart Signal
## 📢 Rust Signal

`[RINF:DART-SIGNAL]` generates a channel from Dart to Rust.
`[RINF:RUST-SIGNAL]` generates a channel from Rust to Dart.

```proto title="Protobuf"
// [RINF:DART-SIGNAL]
message MyDataInput { ... }
// [RINF:RUST-SIGNAL]
message MyDataOutput { ... }
```

```dart title="Dart"
MyDataInput( ... ).sendSignalToRust();
StreamBuilder(
stream: MyDataOutput.rustSignalStream,
builder: (context, snapshot) {
final rustSignal = snapshot.data;
if (rustSignal == null) {
// Return an empty widget.
}
final myDataOutput = rustSignal.message;
// Return a filled widget.
},
)
```

```rust title="Rust"
let mut receiver = MyDataInput::get_dart_signal_receiver()?;
while let Some(dart_signal) = receiver.recv().await {
let message: MyDataInput = dart_signal.message;
// Custom Rust logic here
}
MyDataOutput { ... }.send_signal_to_dart();
```

Use `[RINF:DART-SIGNAL-BINARY]` to include binary data without the overhead of serialization.
Use `[RINF:RUST-SIGNAL-BINARY]` to include binary data without the overhead of serialization.

```proto title="Protobuf"
// [RINF:DART-SIGNAL-BINARY]
message MyDataInput { ... }
// [RINF:RUST-SIGNAL-BINARY]
message MyDataOutput { ... }
```

```dart title="Dart"
final binary = Uint8List(64);
MyDataInput( ... ).sendSignalToRust(binary);
StreamBuilder(
stream: MyDataOutput.rustSignalStream,
builder: (context, snapshot) {
final rustSignal = snapshot.data;
if (rustSignal == null) {
// Return an empty widget.
}
final myDataOutput = rustSignal.message;
// Return a filled widget.
},
)
```

```rust title="Rust"
let mut receiver = MyDataInput::get_dart_signal_receiver()?;
while let Some(dart_signal) = receiver.recv().await {
let message: MyDataInput = dart_signal.message;
let binary: Vec<u8> = dart_signal.binary;
// Custom Rust logic here
}
let binary: Vec<u8> = vec![0; 64];
MyDataOutput { ... }.send_signal_to_dart(binary);
```

## 📢 Rust Signal
## 📭 Dart Signal

`[RINF:RUST-SIGNAL]` generates a channel from Rust to Dart.
`[RINF:DART-SIGNAL]` generates a channel from Dart to Rust.

```proto title="Protobuf"
// [RINF:RUST-SIGNAL]
message MyDataOutput { ... }
// [RINF:DART-SIGNAL]
message MyDataInput { ... }
```

```dart title="Dart"
final stream = MyDataOutput.rustSignalStream;
await for (final rustSignal in stream) {
MyDataOutput message = rustSignal.message;
// Custom Dart logic here
}
MyDataInput( ... ).sendSignalToRust();
```

```rust title="Rust"
MyDataOutput { ... }.send_signal_to_dart();
let mut receiver = MyDataInput::get_dart_signal_receiver()?;
while let Some(dart_signal) = receiver.recv().await {
let message: MyDataInput = dart_signal.message;
// Custom Rust logic here
}
```

Use `[RINF:RUST-SIGNAL-BINARY]` to include binary data without the overhead of serialization.
Use `[RINF:DART-SIGNAL-BINARY]` to include binary data without the overhead of serialization.

```proto title="Protobuf"
// [RINF:RUST-SIGNAL-BINARY]
message MyDataOutput { ... }
// [RINF:DART-SIGNAL-BINARY]
message MyDataInput { ... }
```

```dart title="Dart"
final stream = MyDataOutput.rustSignalStream;
await for (final rustSignal in stream) {
MyDataOutput message = rustSignal.message;
Uint8List binary = rustSignal.binary;
// Custom Dart logic here
}
final binary = Uint8List(64);
MyDataInput( ... ).sendSignalToRust(binary);
```

```rust title="Rust"
let binary: Vec<u8> = vec![0; 64];
MyDataOutput { ... }.send_signal_to_dart(binary);
let mut receiver = MyDataInput::get_dart_signal_receiver()?;
while let Some(dart_signal) = receiver.recv().await {
let message: MyDataInput = dart_signal.message;
let binary: Vec<u8> = dart_signal.binary;
// Custom Rust logic here
}
```

0 comments on commit 412adfb

Please sign in to comment.