Angelus.Spice.WorkerProtocol (Angelus v0.0.2)

Copy Markdown View Source

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

request_id()

@type request_id() :: non_neg_integer()

Functions

coerce_state(arg1)

@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.

decode(binary)

@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.

encode_clear_kernels(id)

@spec encode_clear_kernels(request_id()) :: binary()

Encodes a clear_kernels request.

encode_load_default_kernels(id, base_path)

@spec encode_load_default_kernels(request_id(), String.t()) :: binary()

Encodes a load_default_kernels request.

encode_load_kernels(id, paths)

@spec encode_load_kernels(request_id(), [String.t()]) :: binary()

Encodes a load_kernels request with explicit paths.

encode_ping(id)

@spec encode_ping(request_id()) :: binary()

Encodes a ping request.

encode_state(id, spice_target, et)

@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"

encode_utc_to_et(id, iso8601)

@spec encode_utc_to_et(request_id(), String.t()) :: binary()

Encodes a utc_to_et request.