Class: Ruact::Testing::FlightWireParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ruact/testing/flight_wire_parser.rb

Overview

Parses a Flight wire byte string into an ordered array of row records.

Used by the structural Flight matchers to assert on parsed semantics rather than literal bytes. Pure function — no I/O, no global state, no Thread.current.

Examples:

wire = "1:I[\"/L.jsx\",\"L\",[\"/L.jsx\"]]\n0:[\"$\",\"$L1\",null,{}]\n"
Ruact::Testing::FlightWireParser.parse(wire)
# => [
#      { id: 1, class: :import, payload: ["/L.jsx", "L", ["/L.jsx"]], raw: "1:I...\n" },
#      { id: 0, class: :model,  payload: ["$", "$L1", nil, {}],       raw: "0:[\"$\"...\n" }
#    ]

Class Method Summary collapse

Class Method Details

.parse(wire) ⇒ Array<Hash>

Parse a complete Flight wire byte string.

Parameters:

  • wire (String)

    the raw bytes emitted by Ruact::Flight::Renderer.

Returns:

  • (Array<Hash>)

    one hash per row, in wire order. See class docs for the hash shape (:id, :class, :payload, :raw).

Raises:



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ruact/testing/flight_wire_parser.rb', line 40

def self.parse(wire)
  rows = []
  scanner = StringScanner.new(wire)

  until scanner.eos?
    start_offset = scanner.pos
    rows << parse_row(scanner, start_offset)
  end

  rows
end