From a10e4ddb8914c466572940629e5743b9838ab651 Mon Sep 17 00:00:00 2001 From: narawat Date: Sun, 5 Jul 2026 19:46:04 +0700 Subject: [PATCH 1/4] fix string error --- src/msghandler.jl | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/msghandler.jl b/src/msghandler.jl index 6ac75fa..92c595b 100644 --- a/src/msghandler.jl +++ b/src/msghandler.jl @@ -446,25 +446,26 @@ function smartpack( )::Tuple{msg_envelope_v1, String} where {T1<:Any} # Log start of send operation - log_trace(correlation_id, "Starting smartpack for subject: $subject") + # log_trace(correlation_id, "Starting smartpack for subject: $subject") # Process each payload in the list payloads = msg_payload_v1[] for (dataname, payload_data, payload_type) in data # @show dataname typeof(payload_data) + @info "msghandler smartpack() 1" @__LINE__ # Serialize data based on type. use bytes as medium for every datatype payload_bytes = _serialize_data(payload_data, payload_type) - + @info "msghandler smartpack() 2" @__LINE__ payload_size = length(payload_bytes) # Calculate payload size in bytes - log_trace(correlation_id, "Serialized payload '$dataname' (payload_type: $payload_type) size: $payload_size bytes") # Log payload size + # log_trace(correlation_id, "Serialized payload '$dataname' (payload_type: $payload_type) size: $payload_size bytes") # Log payload size # Decision: Direct vs Link if payload_size < size_threshold # Check if payload is small enough for direct transport # Direct path - Base64 encode and include in message envelope payload_b64 = Base64.base64encode(payload_bytes) # Encode bytes as base64 string - log_trace(correlation_id, "Using direct transport for $payload_size bytes") # Log transport choice - + # log_trace(correlation_id, "Using direct transport for $payload_size bytes") # Log transport choice + @info "msghandler smartpack() 3" @__LINE__ # Determine encoding based on payload_type encoding = "base64" if payload_type == "jsontable" @@ -486,8 +487,9 @@ function smartpack( ) push!(payloads, payload) else + @info "msghandler smartpack() 4" @__LINE__ # Link path - Upload to HTTP server, include URL in message envelope - log_trace(correlation_id, "Using link transport, uploading to fileserver") # Log link transport choice + # log_trace(correlation_id, "Using link transport, uploading to fileserver") # Log link transport choice # Upload to HTTP server response = fileserver_upload_handler(fileserver_url, dataname, payload_bytes) @@ -497,7 +499,7 @@ function smartpack( end url = response["url"] # URL for the uploaded data - log_trace(correlation_id, "Uploaded to URL: $url") # Log successful upload + # log_trace(correlation_id, "Uploaded to URL: $url") # Log successful upload # Determine encoding based on payload_type encoding = "none" @@ -520,6 +522,7 @@ function smartpack( ) push!(payloads, payload) end + @info "msghandler smartpack() 5" @__LINE__ end # Create msg_envelope_v1 with all payloads @@ -549,7 +552,7 @@ function smartpack( # # Publish message to NATS using existing connection # publish_message(NATS_connection, subject, env_json_str, correlation_id) # end - + @info "msghandler smartpack() 6" @__LINE__ return (env, env_json_str) end @@ -636,22 +639,22 @@ function _serialize_data(data::Any, payload_type::String) json_obj = JSON.parse(json_str_2) """ - if payload_type == "text" # Text data - convert to UTF-8 bytes - if isa(data, String) - data_bytes = Vector{UInt8}(data) # Convert string to UTF-8 bytes - return data_bytes - else - error("Text data must be a String") - end + if data <: AbstractString # Text data - convert to UTF-8 bytes + @info "msghandler _serialize_data() 1" @__LINE__ + data_bytes = Vector{UInt8}(string(data)) # Convert string to UTF-8 bytes + return data_bytes elseif payload_type == "dictionary" # JSON data - serialize directly + @info "msghandler _serialize_data() 2" @__LINE__ json_str = JSON.json(data) # Convert Julia data to JSON string json_str_bytes = Vector{UInt8}(json_str) # Convert JSON string to bytes return json_str_bytes elseif payload_type == "arrowtable" # Arrow table data - convert to Arrow IPC stream + @info "msghandler _serialize_data() 3" @__LINE__ io = IOBuffer() # Create in-memory buffer Arrow.write(io, data) # Write data as Arrow IPC stream to buffer return take!(io) # Return the buffer contents as bytes elseif payload_type == "jsontable" # JSON table data - convert to JSON + @info "msghandler _serialize_data() 4" @__LINE__ # data can be Vector{NamedTuple}, Vector{Dict}, or DataFrame # If DataFrame, convert to Vector{Dict} first if isa(data, DataFrame) @@ -667,29 +670,34 @@ function _serialize_data(data::Any, payload_type::String) json_str = JSON.json(rows) return Vector{UInt8}(json_str) else + @info "msghandler _serialize_data() 5" @__LINE__ # Already Vector{NamedTuple} or Vector{Dict} json_str = JSON.json(data) return Vector{UInt8}(json_str) end elseif payload_type == "image" # Image data - treat as binary + @info "msghandler _serialize_data() 6" @__LINE__ if isa(data, Vector{UInt8}) return data # Return binary data directly else error("Image data must be Vector{UInt8}") end elseif payload_type == "audio" # Audio data - treat as binary + @info "msghandler _serialize_data() 7" @__LINE__ if isa(data, Vector{UInt8}) return data # Return binary data directly else error("Audio data must be Vector{UInt8}") end elseif payload_type == "video" # Video data - treat as binary + @info "msghandler _serialize_data() 8" @__LINE__ if isa(data, Vector{UInt8}) return data # Return binary data directly else error("Video data must be Vector{UInt8}") end elseif payload_type == "binary" # Binary data - treat as binary + @info "msghandler _serialize_data() 9" @__LINE__ if isa(data, IOBuffer) # Check if data is an IOBuffer return take!(data) # Return buffer contents as bytes elseif isa(data, Vector{UInt8}) # Check if data is already binary @@ -698,6 +706,7 @@ function _serialize_data(data::Any, payload_type::String) error("Binary data must be binary (Vector{UInt8} or IOBuffer)") end else # Unknown type + @info "msghandler _serialize_data() 10" @__LINE__ error("Unknown payload_type: $payload_type") end end From 69ccb9990fc8cfcdb0c8ac0c8aec146c70d43e68 Mon Sep 17 00:00:00 2001 From: narawat Date: Sun, 5 Jul 2026 20:11:19 +0700 Subject: [PATCH 2/4] update --- Project.toml | 2 +- src/msghandler.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index a1b711b..6488c5e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "msghandler" uuid = "f2724d33-f338-4a57-b9f8-1be882570d10" -version = "1.2.0" +version = "1.2.1" authors = ["narawat "] [deps] diff --git a/src/msghandler.jl b/src/msghandler.jl index 92c595b..b3cd123 100644 --- a/src/msghandler.jl +++ b/src/msghandler.jl @@ -639,7 +639,7 @@ function _serialize_data(data::Any, payload_type::String) json_obj = JSON.parse(json_str_2) """ - if data <: AbstractString # Text data - convert to UTF-8 bytes + if payload_type == "text" # Text data - convert to UTF-8 bytes @info "msghandler _serialize_data() 1" @__LINE__ data_bytes = Vector{UInt8}(string(data)) # Convert string to UTF-8 bytes return data_bytes From 775049ae5fa8c341efe830707f5511f3736c8d03 Mon Sep 17 00:00:00 2001 From: narawat Date: Thu, 9 Jul 2026 07:47:52 +0700 Subject: [PATCH 3/4] update --- src/msghandler.jl | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/msghandler.jl b/src/msghandler.jl index b3cd123..ed374e9 100644 --- a/src/msghandler.jl +++ b/src/msghandler.jl @@ -446,17 +446,17 @@ function smartpack( )::Tuple{msg_envelope_v1, String} where {T1<:Any} # Log start of send operation - # log_trace(correlation_id, "Starting smartpack for subject: $subject") + log_trace(correlation_id, "Starting smartpack for subject: $subject") # Process each payload in the list payloads = msg_payload_v1[] for (dataname, payload_data, payload_type) in data # @show dataname typeof(payload_data) - @info "msghandler smartpack() 1" @__LINE__ + # @info "msghandler smartpack() 1" @__LINE__ # Serialize data based on type. use bytes as medium for every datatype payload_bytes = _serialize_data(payload_data, payload_type) - @info "msghandler smartpack() 2" @__LINE__ + # @info "msghandler smartpack() 2" @__LINE__ payload_size = length(payload_bytes) # Calculate payload size in bytes # log_trace(correlation_id, "Serialized payload '$dataname' (payload_type: $payload_type) size: $payload_size bytes") # Log payload size @@ -465,7 +465,7 @@ function smartpack( # Direct path - Base64 encode and include in message envelope payload_b64 = Base64.base64encode(payload_bytes) # Encode bytes as base64 string # log_trace(correlation_id, "Using direct transport for $payload_size bytes") # Log transport choice - @info "msghandler smartpack() 3" @__LINE__ + # @info "msghandler smartpack() 3" @__LINE__ # Determine encoding based on payload_type encoding = "base64" if payload_type == "jsontable" @@ -487,7 +487,7 @@ function smartpack( ) push!(payloads, payload) else - @info "msghandler smartpack() 4" @__LINE__ + # @info "msghandler smartpack() 4" @__LINE__ # Link path - Upload to HTTP server, include URL in message envelope # log_trace(correlation_id, "Using link transport, uploading to fileserver") # Log link transport choice @@ -522,7 +522,7 @@ function smartpack( ) push!(payloads, payload) end - @info "msghandler smartpack() 5" @__LINE__ + # @info "msghandler smartpack() 5" @__LINE__ end # Create msg_envelope_v1 with all payloads @@ -552,7 +552,7 @@ function smartpack( # # Publish message to NATS using existing connection # publish_message(NATS_connection, subject, env_json_str, correlation_id) # end - @info "msghandler smartpack() 6" @__LINE__ + # @info "msghandler smartpack() 6" @__LINE__ return (env, env_json_str) end @@ -640,21 +640,22 @@ function _serialize_data(data::Any, payload_type::String) """ if payload_type == "text" # Text data - convert to UTF-8 bytes - @info "msghandler _serialize_data() 1" @__LINE__ + # @info "msghandler _serialize_data() 1" @__LINE__ data_bytes = Vector{UInt8}(string(data)) # Convert string to UTF-8 bytes return data_bytes elseif payload_type == "dictionary" # JSON data - serialize directly - @info "msghandler _serialize_data() 2" @__LINE__ + # @info "msghandler _serialize_data() 2" @__LINE__ json_str = JSON.json(data) # Convert Julia data to JSON string json_str_bytes = Vector{UInt8}(json_str) # Convert JSON string to bytes return json_str_bytes elseif payload_type == "arrowtable" # Arrow table data - convert to Arrow IPC stream - @info "msghandler _serialize_data() 3" @__LINE__ + # @info "msghandler _serialize_data() 3" @__LINE__ io = IOBuffer() # Create in-memory buffer Arrow.write(io, data) # Write data as Arrow IPC stream to buffer return take!(io) # Return the buffer contents as bytes elseif payload_type == "jsontable" # JSON table data - convert to JSON - @info "msghandler _serialize_data() 4" @__LINE__ + # @info "msghandler _serialize_data() 4" @__LINE__ + # data can be Vector{NamedTuple}, Vector{Dict}, or DataFrame # If DataFrame, convert to Vector{Dict} first if isa(data, DataFrame) @@ -670,34 +671,35 @@ function _serialize_data(data::Any, payload_type::String) json_str = JSON.json(rows) return Vector{UInt8}(json_str) else - @info "msghandler _serialize_data() 5" @__LINE__ + # @info "msghandler _serialize_data() 5" @__LINE__ + # Already Vector{NamedTuple} or Vector{Dict} json_str = JSON.json(data) return Vector{UInt8}(json_str) end elseif payload_type == "image" # Image data - treat as binary - @info "msghandler _serialize_data() 6" @__LINE__ + # @info "msghandler _serialize_data() 6" @__LINE__ if isa(data, Vector{UInt8}) return data # Return binary data directly else error("Image data must be Vector{UInt8}") end elseif payload_type == "audio" # Audio data - treat as binary - @info "msghandler _serialize_data() 7" @__LINE__ + # @info "msghandler _serialize_data() 7" @__LINE__ if isa(data, Vector{UInt8}) return data # Return binary data directly else error("Audio data must be Vector{UInt8}") end elseif payload_type == "video" # Video data - treat as binary - @info "msghandler _serialize_data() 8" @__LINE__ + # @info "msghandler _serialize_data() 8" @__LINE__ if isa(data, Vector{UInt8}) return data # Return binary data directly else error("Video data must be Vector{UInt8}") end elseif payload_type == "binary" # Binary data - treat as binary - @info "msghandler _serialize_data() 9" @__LINE__ + # @info "msghandler _serialize_data() 9" @__LINE__ if isa(data, IOBuffer) # Check if data is an IOBuffer return take!(data) # Return buffer contents as bytes elseif isa(data, Vector{UInt8}) # Check if data is already binary @@ -706,7 +708,7 @@ function _serialize_data(data::Any, payload_type::String) error("Binary data must be binary (Vector{UInt8} or IOBuffer)") end else # Unknown type - @info "msghandler _serialize_data() 10" @__LINE__ + # @info "msghandler _serialize_data() 10" @__LINE__ error("Unknown payload_type: $payload_type") end end From b0b835d6b94a27f0787cf287a378d575d19bcd50 Mon Sep 17 00:00:00 2001 From: narawat Date: Thu, 9 Jul 2026 07:50:45 +0700 Subject: [PATCH 4/4] update --- Manifest.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index fb7ed22..28bbb38 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -2,7 +2,7 @@ julia_version = "1.12.6" manifest_format = "2.0" -project_hash = "866f6d0804412d52eacd6423616500484f0060f0" +project_hash = "077e6beb148583a11d2d65eed055b8ff4a7db4b6" [[deps.AliasTables]] deps = ["PtrArrays", "Random"] @@ -812,7 +812,7 @@ version = "1.0.21+0" deps = ["Arrow", "Base64", "DataFrames", "Dates", "GeneralUtils", "HTTP", "JSON", "NATS", "PrettyPrinting", "Revise", "UUIDs"] path = "." uuid = "f2724d33-f338-4a57-b9f8-1be882570d10" -version = "0.5.6" +version = "1.2.1" [[deps.nghttp2_jll]] deps = ["Artifacts", "Libdl"]