Fix binary protobuf encoding for JSON serializer

- Use base64-encoded binary in JSON payload instead of {:binary, data} tuples
- V1.JSONSerializer cannot encode tuples, needs plain JSON objects
- Agent already sends/expects base64-encoded binary in 'binary' key
This commit is contained in:
Graham McIntire 2026-01-16 18:36:24 -06:00
parent 9b88a32f33
commit 6b7a3ba36e
No known key found for this signature in database

View file

@ -65,19 +65,21 @@ defmodule ToweropsWeb.AgentChannel do
job_list = %AgentJobList{jobs: jobs}
binary = AgentJobList.encode(job_list)
push(socket, "jobs", {:binary, binary})
push(socket, "jobs", %{binary: Base.encode64(binary)})
{:noreply, socket}
end
@impl true
def handle_in("result", {:binary, binary}, socket) do
def handle_in("result", %{"binary" => binary_b64}, socket) do
binary = Base.decode64!(binary_b64)
result = SnmpResult.decode(binary)
process_snmp_result(socket.assigns.organization_id, result)
{:noreply, socket}
end
@impl true
def handle_in("heartbeat", {:binary, binary}, socket) do
def handle_in("heartbeat", %{"binary" => binary_b64}, socket) do
binary = Base.decode64!(binary_b64)
heartbeat = AgentHeartbeat.decode(binary)
metadata = %{
@ -91,7 +93,8 @@ defmodule ToweropsWeb.AgentChannel do
end
@impl true
def handle_in("error", {:binary, binary}, socket) do
def handle_in("error", %{"binary" => binary_b64}, socket) do
binary = Base.decode64!(binary_b64)
error = AgentError.decode(binary)
Logger.error("Agent job error",