From b8339897f3cc822d997c8cc92f48bfd1c0718444 Mon Sep 17 00:00:00 2001 From: narawat Date: Sun, 24 May 2026 12:39:19 +0700 Subject: [PATCH] update doc --- AI_prompt.md | 9 +++++ README.md | 56 ++++++++++++++++++++++++++--- test/test_js_mix_payloads_sender.js | 2 +- 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/AI_prompt.md b/AI_prompt.md index b485996..759d058 100644 --- a/AI_prompt.md +++ b/AI_prompt.md @@ -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 + diff --git a/README.md b/README.md index c87a7ca..5300e06 100644 --- a/README.md +++ b/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. diff --git a/test/test_js_mix_payloads_sender.js b/test/test_js_mix_payloads_sender.js index 5123c56..d5dc950 100644 --- a/test/test_js_mix_payloads_sender.js +++ b/test/test_js_mix_payloads_sender.js @@ -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');