The reference decoder of the binary canvas (spec/10 §4.8), copied from visualize's
Visualize.Backend.CanvasBinary.Decoder and written from spec/10 §4.2–§4.3 and §4.9,
not from the encoder, so decode(encode(x)) is a round trip that tests both
(visualize D-36). Where visualize raised on a bad byte, this answers it: a test or a
host reading a stream it did not write gets a value.
decode/1 answers the records of a stream in order:
{:path, commands}, the commands of any path record (path,path32,path_cubic,path_cubic32,cubic_run) asMacaw.Draw.IR.Pathcommands;{:circles, [{cx, cy, r}]},{:rects, [{x, y, w, h}]};{:style, map}, itsfill,stroke(RGBA tuples),stroke_widthandopacity,nilwhere absent, withnon_scaling: true,fill_paint:andstroke_paint:under bits 4–6;{:transform, op},op {:translate, tx, ty},{:translate_scale, tx, ty, sx, sy}or{:matrix, a, b, c, d, e, f};{:version, v},{:paint, index, paint}(%{type: :linear | :radial, geometry, stops: [{at, rgba}]}or%{type: :hatch, pattern, geometry, color, background}),{:box, {x, y, w, h}},{:effect, :shadow, radius, {dx, dy}, rgba}or{:effect, :blur, radius},{:motion, json},:motion_end;{:paint_state, map}, itsfill_alpha,stroke_alpha,cap,join,dashand, under bit0x20,dash_offset,nilwhere absent;{:clip, :inside | :outside},{:blend, word}(the CSS word);:save,:restore,:fill,:stroke;{:incremental, mode, dx, dy, viewport, regions},{:full_redraw, viewport, records}and{:clearing, mode, dx, dy, viewport, regions}, each region{{x, y, w, h}, records}andmode :in_place,:scroll_x,:scroll_yor:scroll_xy.
Refusals name the byte and its offset: {:opcode, byte, offset} for an unknown
opcode, {:sub_opcode, byte, offset}, {:kind, byte, offset} for a transform, paint,
effect or incremental mode of no known kind, {:version, v, offset} for a version above
the decoder's own (version:, 5 by default), {:value, byte, offset} for a clip keep,
blend mode, cap, join or hatch pattern of no known value, and {:truncated, offset} for
a record cut short, the offset where its bytes ran out.
Summary
Functions
The records of a stream, in order, or the refusal of its first bad byte. version:
is the highest version this decoder knows, 5 by default.
The one path record of a stream as a Macaw.Draw.IR.Path; a stream of anything else is
{:error, :not_a_path}.
Types
@type refusal() :: {:opcode | :sub_opcode | :kind | :version | :value, byte(), non_neg_integer()} | {:truncated, non_neg_integer()}
A refusal: what was refused and where.
Functions
The records of a stream, in order, or the refusal of its first bad byte. version:
is the highest version this decoder knows, 5 by default.
iex> Macaw.Draw.Render.Binary.Decoder.decode(<<0x30, 0x40, 0x31>>)
{:ok, [:save, :fill, :restore]}
iex> Macaw.Draw.Render.Binary.Decoder.decode(<<0x30, 0x99>>)
{:error, {:opcode, 0x99, 1}}
@spec decode_path(binary()) :: {:ok, Macaw.Draw.IR.Path.t()} | {:error, term()}
The one path record of a stream as a Macaw.Draw.IR.Path; a stream of anything else is
{:error, :not_a_path}.