# `Juggernaut.Store.Codec`
[🔗](https://github.com/holsee/juggernaut/blob/v0.4.0/lib/juggernaut/store/codec.ex#L1)

Encodes the structs of design notes §14.1 as JSON-ready maps with string keys, and
decodes them back.

Decoding never uses `keys: :atoms`. Enumerated values (statuses, lanes, operators, ...)
are matched against their known lists; an unknown value fails the decode. Module and
function names are atoms created from our own run files, which only ever name modules
and functions of the project under test.

`decode/2` returns `{:error, reason}` instead of raising, for a missing field, an unknown
value or a value of the wrong type alike, so a reader can skip or rebuild what it cannot
read (§7: never crash on old data). Every field is checked against its §14.1 type (a
string, a non-negative or positive integer, a number, a list or map of those), so a
decoded struct always matches the typespecs the views code against.

# `kind`

```elixir
@type kind() :: :run | :mutant | :result | :test_ref | :phase | :summary
```

# `decode`

```elixir
@spec decode(kind(), map()) :: {:ok, struct()} | {:error, String.t()}
```

Decodes a map written by `encode/1` into the struct of `kind`.

# `encode`

```elixir
@spec encode(struct()) :: map()
```

Encodes a struct as a map with string keys. A `Run` is encoded without mutants and results.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
