update doc
This commit is contained in:
@@ -282,6 +282,15 @@ I want to add:
|
||||
|
||||
|
||||
|
||||
read the following files:
|
||||
- ./README.md
|
||||
- ./src/msghandler.jl
|
||||
- ./test/test_julia_mix_payloads_sender.jl
|
||||
- ./src/msghandler-csr.js
|
||||
I want to:
|
||||
1) add sending jsontable and arrowtable julia example in README.md
|
||||
2) add sending jsontable and image Javascript example in README.md
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
56
README.md
56
README.md
@@ -263,8 +263,11 @@ const { smartpack, smartunpack, plikOneshotUpload, fetchWithBackoff } = msghandl
|
||||
// Data format: [[dataname, data, type], ...]
|
||||
const payload1 = ["test_message", "Hello World", "text"];
|
||||
const payload2 = ["config_data", { key: "value" }, "dictionary"];
|
||||
const payload3 = ["table_data", [{id: 1, name: "Alice"}], "jsontable"];
|
||||
const image_bytes = new Uint8Array([1, 2, 3, ...]); // Image data
|
||||
const payload4 = ["user_avatar", image_bytes, "image"];
|
||||
|
||||
const payloads = [payload1, payload2]; // Array of arrays
|
||||
const payloads = [payload1, payload2, payload3, payload4]; // Array of arrays
|
||||
|
||||
// Step 1: Create the message envelope (transport-agnostic)
|
||||
const [envelope, envelopeJsonStr] = await msghandlerCSR.smartpack("test.topic", payloads, {
|
||||
@@ -463,7 +466,7 @@ env, env_json_str = smartpack("/device/config", data)
|
||||
|
||||
### Example 3: Table Data (Arrow IPC - Julia Only)
|
||||
|
||||
Send tabular data using Apache Arrow IPC format.
|
||||
Send tabular data using Apache Arrow IPC format for efficient binary serialization:
|
||||
|
||||
```julia
|
||||
using msghandler
|
||||
@@ -479,7 +482,25 @@ data = [("students", df, "arrowtable")]
|
||||
env, env_json_str = smartpack("/data/analysis", data)
|
||||
```
|
||||
|
||||
### Example 3b: Table Data (JSON - JavaScript Compatible)
|
||||
### Example 3b: Table Data (JSON - Julia Compatible)
|
||||
|
||||
For cross-platform compatibility or when Arrow IPC is not needed, use `jsontable`:
|
||||
|
||||
```julia
|
||||
using msghandler
|
||||
using DataFrames
|
||||
|
||||
df = DataFrame(
|
||||
id = [1, 2, 3],
|
||||
name = ["Alice", "Bob", "Charlie"],
|
||||
score = [95, 88, 92]
|
||||
)
|
||||
|
||||
data = [("students", df, "jsontable")]
|
||||
env, env_json_str = smartpack("/data/analysis", data)
|
||||
```
|
||||
|
||||
### Example 3c: Table Data (JSON - JavaScript Compatible)
|
||||
|
||||
For JavaScript frontend, use `jsontable` instead of `arrowtable`:
|
||||
|
||||
@@ -495,7 +516,34 @@ const [envelope, envelopeJsonStr] = await msghandlerCSR.smartpack("/data/analysi
|
||||
]);
|
||||
```
|
||||
|
||||
### Example 4: Request-Response Pattern
|
||||
### Example 4: Image Transmission (Julia)
|
||||
|
||||
Send image data directly in messages:
|
||||
|
||||
```julia
|
||||
using msghandler
|
||||
|
||||
# Read image file
|
||||
image_path = "./path/to/image.jpg"
|
||||
image_data = read(image_path)
|
||||
|
||||
data = [("user_avatar", image_data, "image")]
|
||||
env, env_json_str = smartpack("/chat/room1", data; fileserver_url="http://localhost:8080")
|
||||
```
|
||||
|
||||
### Example 5: Image Transmission (JavaScript)
|
||||
|
||||
Send image data directly in messages:
|
||||
|
||||
```javascript
|
||||
const image_data = new Uint8Array([1, 2, 3, ...]); // Image bytes
|
||||
|
||||
const [envelope, envelopeJsonStr] = await msghandlerCSR.smartpack("/chat/room1", [
|
||||
["user_avatar", image_data, "image"]
|
||||
]);
|
||||
```
|
||||
|
||||
### Example 6: Request-Response Pattern
|
||||
|
||||
Bi-directional communication with reply-to support.
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* any combination and any number of mixed content can be sent correctly.
|
||||
*/
|
||||
|
||||
const msghandler = require('../src/msghandler-csr.js');
|
||||
const msghandler = require('../src/msghandler-csr.js').default;
|
||||
const crypto = require('crypto');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
Reference in New Issue
Block a user