Encodes requests and decodes responses for the spice_worker Port protocol.
Frame format (matching Erlang packet: 4):
[4 bytes big-endian uint32: payload length][payload: UTF-8 JSON]
Elixir opens the Port with packet: 4, so the VM handles the framing
automatically. This module only deals with the JSON payload layer.
Request schema: %{"id" => integer, "op" => string, ...op-specific fields...}
Response schema (success): %{"id" => integer, "ok" => true, "result" => term}
Response schema (error): %{"id" => integer, "ok" => false, "error" => string}
Summary
Functions
Coerces a state result map (string keys from JSON) into an Elixir map
with atom keys and typed values.
Decodes a raw binary response from the worker.
Encodes a clear_kernels request.
Encodes a load_default_kernels request.
Encodes a load_kernels request with explicit paths.
Encodes a ping request.
Encodes a state request.
Encodes a utc_to_et request.
Types
@type request_id() :: non_neg_integer()
Functions
@spec coerce_state(map()) :: {:ok, map()} | {:error, :invalid_state_result}
@spec coerce_state(term()) :: {:error, :invalid_state_result}
Coerces a state result map (string keys from JSON) into an Elixir map
with atom keys and typed values.
@spec decode(binary()) :: {:ok, request_id(), term()} | {:error, request_id(), term()} | {:error, :decode_error, binary()}
@spec decode(term()) :: {:error, :decode_error, term()}
Decodes a raw binary response from the worker.
Returns {:ok, id, result} or {:error, id, reason}.
Returns {:error, :decode_error, binary} if JSON is malformed.
@spec encode_clear_kernels(request_id()) :: binary()
Encodes a clear_kernels request.
@spec encode_load_default_kernels(request_id(), String.t()) :: binary()
Encodes a load_default_kernels request.
@spec encode_load_kernels(request_id(), [String.t()]) :: binary()
Encodes a load_kernels request with explicit paths.
@spec encode_ping(request_id()) :: binary()
Encodes a ping request.
@spec encode_state(request_id(), String.t(), float()) :: binary()
Encodes a state request.
Parameters are fixed for v0.1: observer: "EARTH" frame: "ECLIPJ2000" abcorr: "LT+S"
@spec encode_utc_to_et(request_id(), String.t()) :: binary()
Encodes a utc_to_et request.