Juggernaut.Store.Codec (Juggernaut v0.4.0)

Copy Markdown View Source

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.

Summary

Functions

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

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

Types

kind()

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

Functions

decode(kind, map)

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

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

encode(run)

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

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