update
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
module NATSBridge
|
module NATSBridge
|
||||||
|
|
||||||
using NATS, JSON, Arrow, HTTP, UUIDs, Dates
|
using NATS, JSON, Arrow, HTTP, UUIDs, Dates, Base64
|
||||||
# ---------------------------------------------- 100 --------------------------------------------- #
|
# ---------------------------------------------- 100 --------------------------------------------- #
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
@@ -155,7 +155,7 @@ env = smartsend("large.data", data, "arrow")
|
|||||||
# In another process, retrieve and deserialize:
|
# In another process, retrieve and deserialize:
|
||||||
# msg = subscribe(nats_url, "my.subject")
|
# msg = subscribe(nats_url, "my.subject")
|
||||||
# env = json_to_envelope(msg.data)
|
# env = json_to_envelope(msg.data)
|
||||||
# data = _deserialize_data(base64decode(env.payload), env.type)
|
# data = _deserialize_data(Base64.decode(env.payload), env.type)
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
function smartsend(
|
function smartsend(
|
||||||
@@ -183,7 +183,7 @@ function smartsend(
|
|||||||
# Decision: Direct vs Link
|
# Decision: Direct vs Link
|
||||||
if payload_size < size_threshold # Check if payload is small enough for direct transport
|
if payload_size < size_threshold # Check if payload is small enough for direct transport
|
||||||
# Direct path - Base64 encode and send via NATS
|
# Direct path - Base64 encode and send via NATS
|
||||||
payload_b64 = base64encode(payload_bytes) # Encode bytes as base64 string
|
payload_b64 = Base64.encode(payload_bytes) # Encode bytes as base64 string
|
||||||
log_trace(cid, "Using direct transport for $payload_size bytes") # Log transport choice
|
log_trace(cid, "Using direct transport for $payload_size bytes") # Log transport choice
|
||||||
|
|
||||||
env = MessageEnvelope( # Create envelope for direct transport
|
env = MessageEnvelope( # Create envelope for direct transport
|
||||||
@@ -354,7 +354,7 @@ function smartreceive(
|
|||||||
log_trace(env.correlation_id, "Direct transport - decoding payload") # Log direct transport handling
|
log_trace(env.correlation_id, "Direct transport - decoding payload") # Log direct transport handling
|
||||||
|
|
||||||
# Decode Base64 payload
|
# Decode Base64 payload
|
||||||
payload_bytes = base64decode(env.payload) # Decode base64 payload to bytes
|
payload_bytes = Base64.decode(env.payload) # Decode base64 payload to bytes
|
||||||
|
|
||||||
# Deserialize based on type
|
# Deserialize based on type
|
||||||
data = _deserialize_data(payload_bytes, env.type, env.correlation_id, env.metadata) # Convert bytes to Julia data
|
data = _deserialize_data(payload_bytes, env.type, env.correlation_id, env.metadata) # Convert bytes to Julia data
|
||||||
@@ -456,19 +456,19 @@ function _deserialize_data(
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
""" Decode base64 string to bytes
|
# """ Decode base64 string to bytes
|
||||||
This internal function decodes a base64-encoded string back to binary data.
|
# This internal function decodes a base64-encoded string back to binary data.
|
||||||
It's a wrapper around Base64.decode for consistency in the module.
|
# It's a wrapper around Base64.decode for consistency in the module.
|
||||||
|
|
||||||
Arguments:
|
# Arguments:
|
||||||
- `str::String` - Base64-encoded string to decode
|
# - `str::String` - Base64-encoded string to decode
|
||||||
|
|
||||||
Return:
|
# Return:
|
||||||
- Vector{UInt8} - Decoded binary data
|
# - Vector{UInt8} - Decoded binary data
|
||||||
"""
|
# """
|
||||||
function base64decode(str::String)
|
# function base64decode(str::String)
|
||||||
return Base64.decode(str) # Decode base64 string to bytes using Julia's Base64 module
|
# return Base64.decode(str) # Decode base64 string to bytes using Julia's Base64 module
|
||||||
end
|
# end
|
||||||
|
|
||||||
|
|
||||||
""" plik_oneshot_upload - Upload a single file to a plik server using one-shot mode
|
""" plik_oneshot_upload - Upload a single file to a plik server using one-shot mode
|
||||||
|
|||||||
@@ -85,7 +85,8 @@ function test_large_binary_receive()
|
|||||||
log_trace("Received $(file_size) bytes of binary data")
|
log_trace("Received $(file_size) bytes of binary data")
|
||||||
|
|
||||||
# Save received data to a test file
|
# Save received data to a test file
|
||||||
output_path = "test_output.bin"
|
filename = basename(result.envelope.url)
|
||||||
|
output_path = "./new_$filename"
|
||||||
write(output_path, result.data)
|
write(output_path, result.data)
|
||||||
log_trace("Saved received data to $output_path")
|
log_trace("Saved received data to $output_path")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user