Visualize.Backend.CanvasBinary.Decoder (Visualize v0.2.25)

Copy Markdown View Source

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)
  • {:transform, :translate, {tx, ty}}, {:transform, :translate_scale, {tx, ty, sx, sy}}, {:transform, :matrix, {a, b, c, d, e, f}}
  • :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.

Summary

Functions

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.

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

Functions

decode(binary)

@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(binary)

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

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