# `Visualize.Backend.CanvasBinary.Decoder`
[🔗](https://github.com/dcoai/Visualize/blob/v0.8.3/lib/visualize/backend/canvas_binary/decoder.ex#L1)

A decoder for the canvas binary format of spec/09 §4 and §5, written against the record
layouts the specification states — not against the encoder — so that
`decode(encode(x))` is a genuine round trip (D-36).

`decode/1` returns the records of a stream in order:

- `{:path, [{x, y}]}`, `{:path_cubic, [command]}` with `Visualize.IR.Path` commands, and
  `{:path32, [{x, y}]}`, `{:path_cubic32, [command]}` for the f32 records (D-73), and
  `{:cubic_run, {x0, y0}, [{x1, y1, x2, y2, x, y}]}` for the cubic run (D-74)
- `{:circles, [{cx, cy, r}]}`, `{:rects, [{x, y, w, h}]}`
- `{:style, %{fill:, stroke:, stroke_width:, opacity:}}` (`nil` for an absent field), with `fill_paint:`
  and `stroke_paint:` indexes under bits 5 and 6
- `{:effect, :shadow, radius, {dx, dy}, {r, g, b, a}}` and `{:effect, :blur, radius}` (§4.3.14)
- `{:motion, json}` and `:motion_end`, a motion span and its end (§4.3.15, §4.3.16, #653)
- the version 3 record `{:paint_state, %{fill_alpha:, stroke_alpha:, cap:, join:, dash:}}`,
  `nil` for an absent field (§4.3.17, #675)
- the version 2 records `{:version, v}`, `{:paint, index, %{type:, geometry: [f32], stops:
  [{at, {r, g, b, a}}]}}` and `{:box, {x, y, w, h}}` (spec/09 §4.3.11–4.3.13)
- `{:transform, :translate, {tx, ty}}`, `{:transform, :translate_scale, {tx, ty, sx, sy}}`,
  `{:transform, :matrix, {a, b, c, d, e, f}}`
- the version 4 records `{:clip, :inside | :outside}` and `{:blend, word}`, the word the
  CSS `mix-blend-mode` one (§4.3.18, §4.3.19, #788)
- `:save`, `:restore`, `:fill`, `:stroke`
- `{:incremental, mode, dx, dy, {x, y, w, h}, [{{x, y, w, h}, records}]}` and `{:full_redraw, viewport, records}`
  for the `0x60` records of `Visualize.Backend.CanvasIncremental`

An unknown opcode or a truncated record raises, since either is an encoder bug.

# `decode`

```elixir
@spec decode(binary()) :: [term()]
```

The records of a stream, in order (spec/09 §4.1, #270). Raises on an unknown opcode or a
truncated record, since either is an encoder bug — or a decoder that has drifted from
the encoder, which is what a consumer's test of its own streams is for.

# `decode_path`

```elixir
@spec decode_path(binary()) :: Visualize.IR.Path.t()
```

The one path record of a stream as a `Visualize.IR.Path`.

---

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