rename to smartpack n smartunpack

This commit is contained in:
2026-05-18 19:30:58 +07:00
parent cc95bc97d3
commit 396e0848da
21 changed files with 323 additions and 314 deletions

View File

@@ -110,7 +110,7 @@ msghandler enables seamless communication across multiple platforms through NATS
using msghandler
data = [("message", "Hello World", "text")]
env, env_json_str = smartsend("/chat/room1", data; broker_url="nats://localhost:4222")
env, env_json_str = smartpack("/chat/room1", data; broker_url="nats://localhost:4222")
println("Message sent!")
```
@@ -120,7 +120,7 @@ println("Message sent!")
import msghandler from './src/msghandler_ssr.js';
const data = [["message", "Hello World", "text"]];
const [env, env_json_str] = await msghandler.smartsend(
const [env, env_json_str] = await msghandler.smartpack(
"/chat/room1",
data,
{ broker_url: "nats://localhost:4222" }
@@ -134,7 +134,7 @@ console.log("Message sent!");
import msghandler from './src/msghandler_csr.js';
const data = [["message", "Hello World", "text"]];
const [env, env_json_str] = await msghandler.smartsend(
const [env, env_json_str] = await msghandler.smartpack(
"/chat/room1",
data,
{ broker_url: "ws://localhost:4222" }
@@ -145,10 +145,10 @@ console.log("Message sent!");
#### Python
```python
from msghandler import smartsend
from msghandler import smartpack
data = [("message", "Hello World", "text")]
env, env_json_str = await smartsend(
env, env_json_str = await smartpack(
"/chat/room1",
data,
broker_url="nats://localhost:4222"
@@ -159,10 +159,10 @@ print("Message sent!")
#### MicroPython
```python
from msghandler import smartsend
from msghandler import smartpack
data = [("message", "Hello World", "text")]
env, env_json_str = smartsend(
env, env_json_str = smartpack(
"/chat/room1",
data,
broker_url="nats://localhost:4222",
@@ -179,12 +179,12 @@ print("Message sent!")
All platforms use the same input/output format for payloads:
**Input format for `smartsend`:**
**Input format for `smartpack`:**
```
[(dataname1, data1, type1), (dataname2, data2, type2), ...]
```
**Output format for `smartreceive`:**
**Output format for `smartunpack`:**
```json
{
"correlation_id": "...",
@@ -204,7 +204,7 @@ All platforms use the same input/output format for payloads:
}
```
### smartsend
### smartpack
Sends data either directly via NATS or via a fileserver URL, depending on payload size.
@@ -213,7 +213,7 @@ Sends data either directly via NATS or via a fileserver URL, depending on payloa
```julia
using msghandler
env, env_json_str = msghandler.smartsend(
env, env_json_str = msghandler.smartpack(
subject::String,
data::AbstractArray{Tuple{String, Any, String}};
broker_url::String = "nats://localhost:4222",
@@ -240,7 +240,7 @@ env, env_json_str = msghandler.smartsend(
```javascript
import msghandler from './src/msghandler_ssr.js';
const [env, env_json_str] = await msghandler.smartsend(
const [env, env_json_str] = await msghandler.smartpack(
subject,
data, // Array of [dataname, data, type] tuples
{
@@ -269,7 +269,7 @@ const [env, env_json_str] = await msghandler.smartsend(
```javascript
import msghandler from './src/msghandler_csr.js';
const [env, env_json_str] = await msghandler.smartsend(
const [env, env_json_str] = await msghandler.smartpack(
subject,
data,
{
@@ -298,7 +298,7 @@ const [env, env_json_str] = await msghandler.smartsend(
```python
from msghandler import msghandler
env, env_json_str = await msghandler.smartsend(
env, env_json_str = await msghandler.smartpack(
subject: str,
data: List[Tuple[str, Any, str]],
broker_url: str = "nats://localhost:4222",
@@ -326,7 +326,7 @@ env, env_json_str = await msghandler.smartsend(
from msghandler import msghandler
# Limited to direct transport (< 100KB threshold)
env, env_json_str = msghandler.smartsend(
env, env_json_str = msghandler.smartpack(
subject,
data, # List of (dataname, data, type) tuples
broker_url="nats://localhost:4222",
@@ -335,7 +335,7 @@ env, env_json_str = msghandler.smartsend(
# Returns: Tuple[Dict, str]
```
### smartreceive
### smartunpack
Receives and processes messages from NATS, handling both direct and link transport.
@@ -344,7 +344,7 @@ Receives and processes messages from NATS, handling both direct and link transpo
```julia
using msghandler
env = msghandler.smartreceive(
env = msghandler.smartunpack(
msg::NATS.Msg;
fileserver_download_handler::Function = _fetch_with_backoff,
max_retries::Int = 5,
@@ -359,7 +359,7 @@ env = msghandler.smartreceive(
```javascript
import msghandler from './src/msghandler_ssr.js';
const env = await msghandler.smartreceive(
const env = await msghandler.smartunpack(
msg,
{
fileserver_download_handler: msghandler.fetchWithBackoff,
@@ -376,7 +376,7 @@ const env = await msghandler.smartreceive(
```javascript
import msghandler from './src/msghandler_csr.js';
const env = await msghandler.smartreceive(
const env = await msghandler.smartunpack(
msg,
{
fileserver_download_handler: msghandler.fetchWithBackoff,
@@ -393,7 +393,7 @@ const env = await msghandler.smartreceive(
```python
from msghandler import msghandler
env = await msghandler.smartreceive(
env = await msghandler.smartunpack(
msg,
fileserver_download_handler=fetch_with_backoff,
max_retries=5,
@@ -408,7 +408,7 @@ env = await msghandler.smartreceive(
```python
from msghandler import msghandler
env = msghandler.smartreceive(
env = msghandler.smartunpack(
msg,
fileserver_download_handler=_sync_fileserver_download,
max_retries=3,
@@ -452,7 +452,7 @@ data = [
("large_document", large_file_data, "binary")
]
env, env_json_str = smartsend("/chat/room1", data; fileserver_url="http://localhost:8080")
env, env_json_str = smartpack("/chat/room1", data; fileserver_url="http://localhost:8080")
```
#### JavaScript (Node.js)
@@ -466,7 +466,7 @@ const data = [
["large_document", largeFileData, "binary"]
];
const [env, env_json_str] = await msghandler.smartsend(
const [env, env_json_str] = await msghandler.smartpack(
"/chat/room1",
data,
{ fileserver_url: 'http://localhost:8080' }
@@ -484,7 +484,7 @@ const data = [
["large_document", largeFileData, "binary"]
];
const [env, env_json_str] = await msghandler.smartsend(
const [env, env_json_str] = await msghandler.smartpack(
"/chat/room1",
data,
{ broker_url: 'ws://localhost:4222', fileserver_url: 'http://localhost:8080' }
@@ -502,7 +502,7 @@ data = [
("large_document", large_file_data, "binary")
]
env, env_json_str = await msghandler.smartsend(
env, env_json_str = await msghandler.smartpack(
"/chat/room1",
data,
fileserver_url="http://localhost:8080"
@@ -525,7 +525,7 @@ config = Dict(
)
data = [("config", config, "dictionary")]
env, env_json_str = smartsend("/device/config", data)
env, env_json_str = smartpack("/device/config", data)
```
#### JavaScript (Node.js)
@@ -539,7 +539,7 @@ const config = {
update_interval: 60
};
const [env, env_json_str] = await msghandler.smartsend(
const [env, env_json_str] = await msghandler.smartpack(
"/device/config",
[["config", config, "dictionary"]]
);
@@ -557,7 +557,7 @@ config = {
}
data = [("config", config, "dictionary")]
env, env_json_str = await msghandler.smartsend("/device/config", data)
env, env_json_str = await msghandler.smartpack("/device/config", data)
```
### Example 3: Table Data (Arrow IPC)
@@ -577,7 +577,7 @@ df = DataFrame(
)
data = [("students", df, "arrowtable")]
env, env_json_str = smartsend("/data/analysis", data)
env, env_json_str = smartpack("/data/analysis", data)
```
#### JavaScript (Node.js)
@@ -591,7 +591,7 @@ const df = [
{ id: 3, name: "Charlie", score: 92 }
];
const [env, env_json_str] = await msghandler.smartsend(
const [env, env_json_str] = await msghandler.smartpack(
"/data/analysis",
[["students", df, "arrowtable"]]
);
@@ -610,7 +610,7 @@ df = pd.DataFrame({
})
data = [("students", df, "arrowtable")]
env, env_json_str = await msghandler.smartsend("/data/analysis", data)
env, env_json_str = await msghandler.smartpack("/data/analysis", data)
```
#### JavaScript (Browser)
@@ -626,7 +626,7 @@ const df = [
{ id: 3, name: "Charlie", score: 92 }
];
const [env, env_json_str] = await msghandler.smartsend(
const [env, env_json_str] = await msghandler.smartpack(
"/data/analysis",
[["students", df, "jsontable"]], // Use jsontable for browser
{ broker_url: 'ws://localhost:4222' }
@@ -643,7 +643,7 @@ Bi-directional communication with reply-to support.
using msghandler
# Requester
env, env_json_str = smartsend(
env, env_json_str = smartpack(
"/device/command",
[("command", Dict("action" => "read_sensor"), "dictionary")];
broker_url="nats://localhost:4222",
@@ -652,9 +652,9 @@ env, env_json_str = smartsend(
# Receiver (in separate application)
msg = NATS.subscription.next()
env = smartreceive(msg)
env = smartunpack(msg)
# Process request and send response
response_env, response_json = smartsend(
response_env, response_json = smartpack(
"/device/response",
[("result", Dict("value" => 42), "dictionary")],
reply_to="/device/command",
@@ -668,7 +668,7 @@ response_env, response_json = smartsend(
import msghandler from './src/msghandler_ssr.js';
// Requester
const [env, env_json_str] = await msghandler.smartsend(
const [env, env_json_str] = await msghandler.smartpack(
"/device/command",
[["command", { action: "read_sensor" }, "dictionary"]],
{ broker_url: 'nats://localhost:4222', reply_to: '/device/response' }
@@ -676,9 +676,9 @@ const [env, env_json_str] = await msghandler.smartsend(
// Receiver (in separate application)
// const msg = await natsConsumer.next();
// const env = await msghandler.smartreceive(msg);
// const env = await msghandler.smartunpack(msg);
// Process request and send response
// const response_env, response_json = await msghandler.smartsend(
// const response_env, response_json = await msghandler.smartpack(
// "/device/response",
// [["result", { value: 42 }, "dictionary"]],
// { reply_to: '/device/command', reply_to_msg_id: env.msg_id }
@@ -691,7 +691,7 @@ const [env, env_json_str] = await msghandler.smartsend(
from msghandler import msghandler
# Requester
env, env_json_str = await msghandler.smartsend(
env, env_json_str = await msghandler.smartpack(
"/device/command",
[("command", {"action": "read_sensor"}, "dictionary")],
broker_url="nats://localhost:4222",
@@ -700,9 +700,9 @@ env, env_json_str = await msghandler.smartsend(
# Receiver (in separate application)
# msg = await nats_consumer.next()
# env = await msghandler.smartreceive(msg)
# env = await msghandler.smartunpack(msg)
# Process request and send response
# response_env, response_json = await msghandler.smartsend(
# response_env, response_json = await msghandler.smartpack(
# "/device/response",
# [("result", {"value": 42}, "dictionary")],
# reply_to="/device/command",
@@ -895,7 +895,7 @@ node build.js
import msghandlerCSR from './dist/msghandler-csr-bundle.js';
// Use the library
const [env, envJson] = await msghandlerCSR.smartsend(
const [env, envJson] = await msghandlerCSR.smartpack(
"/chat/user/v1/message",
[["msg", "Hello", "text"]],
{ broker_url: "wss://nats.example.com" }