This commit is contained in:
2026-02-23 20:50:41 +07:00
parent 0c2cca30ed
commit 263508b8f7
2 changed files with 18 additions and 18 deletions

View File

@@ -1,6 +1,6 @@
name = "NATSBridge" name = "NATSBridge"
uuid = "f2724d33-f338-4a57-b9f8-1be882570d10" uuid = "f2724d33-f338-4a57-b9f8-1be882570d10"
version = "0.4.2" version = "0.4.3"
authors = ["narawat <narawat@gmail.com>"] authors = ["narawat <narawat@gmail.com>"]
[deps] [deps]

View File

@@ -208,7 +208,7 @@ config = {
# Send as dictionary type # Send as dictionary type
data = [("config", config, "dictionary")] data = [("config", config, "dictionary")]
env = smartsend("/device/config", data, nats_url="nats://localhost:4222") env, msg_json_str = smartsend("/device/config", data, nats_url="nats://localhost:4222")
``` ```
#### JavaScript #### JavaScript
@@ -222,7 +222,7 @@ const config = {
update_interval: 60 update_interval: 60
}; };
await smartsend("/device/config", [ const { env, msg_json_str } = await smartsend("/device/config", [
{ dataname: "config", data: config, type: "dictionary" } { dataname: "config", data: config, type: "dictionary" }
]); ]);
``` ```
@@ -239,7 +239,7 @@ config = Dict(
) )
data = [("config", config, "dictionary")] data = [("config", config, "dictionary")]
smartsend("/device/config", data) env, msg_json_str = smartsend("/device/config", data)
``` ```
### Example 2: Sending Binary Data (Image) ### Example 2: Sending Binary Data (Image)
@@ -255,7 +255,7 @@ with open("image.png", "rb") as f:
# Send as binary type # Send as binary type
data = [("user_image", image_data, "binary")] data = [("user_image", image_data, "binary")]
env = smartsend("/chat/image", data, nats_url="nats://localhost:4222") env, msg_json_str = smartsend("/chat/image", data, nats_url="nats://localhost:4222")
``` ```
#### JavaScript #### JavaScript
@@ -267,7 +267,7 @@ const { smartsend } = require('./src/NATSBridge');
const fs = require('fs'); const fs = require('fs');
const image_data = fs.readFileSync('image.png'); const image_data = fs.readFileSync('image.png');
await smartsend("/chat/image", [ const { env, msg_json_str } = await smartsend("/chat/image", [
{ dataname: "user_image", data: image_data, type: "binary" } { dataname: "user_image", data: image_data, type: "binary" }
]); ]);
``` ```
@@ -281,7 +281,7 @@ using NATSBridge
image_data = read("image.png") image_data = read("image.png")
data = [("user_image", image_data, "binary")] data = [("user_image", image_data, "binary")]
smartsend("/chat/image", data) env, msg_json_str = smartsend("/chat/image", data)
``` ```
### Example 3: Request-Response Pattern ### Example 3: Request-Response Pattern
@@ -358,7 +358,7 @@ import os
large_data = os.urandom(2_000_000) # 2MB of random data large_data = os.urandom(2_000_000) # 2MB of random data
# Send with file server URL # Send with file server URL
env = smartsend( env, msg_json_str = smartsend(
"/data/large", "/data/large",
[("large_file", large_data, "binary")], [("large_file", large_data, "binary")],
nats_url="nats://localhost:4222", nats_url="nats://localhost:4222",
@@ -380,7 +380,7 @@ const largeData = new ArrayBuffer(2_000_000);
const view = new Uint8Array(largeData); const view = new Uint8Array(largeData);
view.fill(42); // Fill with some data view.fill(42); // Fill with some data
await smartsend("/data/large", [ const { env, msg_json_str } = await smartsend("/data/large", [
{ dataname: "large_file", data: largeData, type: "binary" } { dataname: "large_file", data: largeData, type: "binary" }
], { ], {
fileserverUrl: "http://localhost:8080", fileserverUrl: "http://localhost:8080",
@@ -396,7 +396,7 @@ using NATSBridge
# Create large data (> 1MB) # Create large data (> 1MB)
large_data = rand(UInt8, 2_000_000) large_data = rand(UInt8, 2_000_000)
env = smartsend( env, msg_json_str = smartsend(
"/data/large", "/data/large",
[("large_file", large_data, "binary")], [("large_file", large_data, "binary")],
fileserver_url="http://localhost:8080" fileserver_url="http://localhost:8080"
@@ -425,7 +425,7 @@ data = [
("user_avatar", image_data, "image") ("user_avatar", image_data, "image")
] ]
env = smartsend("/chat/mixed", data, nats_url="nats://localhost:4222") env, msg_json_str = smartsend("/chat/mixed", data, nats_url="nats://localhost:4222")
``` ```
#### JavaScript #### JavaScript
@@ -435,7 +435,7 @@ const { smartsend } = require('./src/NATSBridge');
const fs = require('fs'); const fs = require('fs');
await smartsend("/chat/mixed", [ const { env, msg_json_str } = await smartsend("/chat/mixed", [
{ {
dataname: "message_text", dataname: "message_text",
data: "Hello with image!", data: "Hello with image!",
@@ -461,7 +461,7 @@ data = [
("user_avatar", image_data, "image") ("user_avatar", image_data, "image")
] ]
smartsend("/chat/mixed", data) env, msg_json_str = smartsend("/chat/mixed", data)
``` ```
### Example 6: Table Data (Arrow IPC) ### Example 6: Table Data (Arrow IPC)
@@ -483,7 +483,7 @@ df = pd.DataFrame({
# Send as table type # Send as table type
data = [("students", df, "table")] data = [("students", df, "table")]
env = smartsend("/data/students", data, nats_url="nats://localhost:4222") env, msg_json_str = smartsend("/data/students", data, nats_url="nats://localhost:4222")
``` ```
#### Julia #### Julia
@@ -500,7 +500,7 @@ df = DataFrame(
) )
data = [("students", df, "table")] data = [("students", df, "table")]
smartsend("/data/students", data) env, msg_json_str = smartsend("/data/students", data)
``` ```
--- ---
@@ -519,7 +519,7 @@ using NATSBridge
# Send dictionary from Julia to JavaScript # Send dictionary from Julia to JavaScript
config = Dict("step_size" => 0.01, "iterations" => 1000) config = Dict("step_size" => 0.01, "iterations" => 1000)
data = [("config", config, "dictionary")] data = [("config", config, "dictionary")]
smartsend("/analysis/config", data, nats_url="nats://localhost:4222") env, msg_json_str = smartsend("/analysis/config", data, nats_url="nats://localhost:4222")
``` ```
#### JavaScript Receiver #### JavaScript Receiver
@@ -544,7 +544,7 @@ for (const payload of envelope.payloads) {
```javascript ```javascript
const { smartsend } = require('./src/NATSBridge'); const { smartsend } = require('./src/NATSBridge');
await smartsend("/data/transfer", [ const { env, msg_json_str } = await smartsend("/data/transfer", [
{ dataname: "message", data: "Hello from JS!", type: "text" } { dataname: "message", data: "Hello from JS!", type: "text" }
]); ]);
``` ```
@@ -568,7 +568,7 @@ for dataname, data, type in envelope["payloads"]:
from nats_bridge import smartsend from nats_bridge import smartsend
data = [("message", "Hello from Python!", "text")] data = [("message", "Hello from Python!", "text")]
smartsend("/chat/python", data) env, msg_json_str = smartsend("/chat/python", data)
``` ```
#### Julia Receiver #### Julia Receiver