Skip to content

Add RawContainerReader: read the SPBXDS container without assuming OWON's JSON schema - #1

Open
alexlegoshin wants to merge 1 commit into
RobThree:mainfrom
alexlegoshin:add-raw-container-reader
Open

Add RawContainerReader: read the SPBXDS container without assuming OWON's JSON schema#1
alexlegoshin wants to merge 1 commit into
RobThree:mainfrom
alexlegoshin:add-raw-container-reader

Conversation

@alexlegoshin

Copy link
Copy Markdown

Problem

BinfileReader assumes every .bin file's JSON metadata follows the OWON/Hanmatek
schema (CHANNEL/DISPLAY/Current_Ratio/Current_Rate, etc.). Files from other
scopes built on the same OEM platform can use the same SPBXDS container but a
different JSON layout — for example, an AKIP-4122/7 capture I ran into uses a
lowercase channel array with Display_Switch/Reference_Zero/Voltage_Rate
fields instead, and its JSON has a trailing comma before the array's closing
bracket. Both of those make BinfileReader.ReadAsync throw:

System.Text.Json.JsonException: The JSON array contains a trailing comma at the end
which is not supported in this mode. Change the reader options. Path: $.channel |
LineNumber: 0 | BytePositionInLine: 686.
   at OwonBinfileReader.BinfileReader.ReadAsync(Stream stream, CancellationToken cancellationToken)

So today there's no way to open such a file with this library at all, even though the
container itself is fully readable.

What this PR adds

A new, independent RawContainerReader that parses only the vendor-agnostic parts of
the SPBXDS container — magic header, JSON length, the JSON text itself (returned
as-is, no assumptions about its schema or strictness), one Int16[] per data segment,
and the optional trailing INFO block:

using OwonBinfileReader.Raw;

var raw = await new RawContainerReader().ReadAsync(@"/path/to/file.bin");
// raw.RawJson    -> the metadata JSON, exactly as stored
// raw.Segments   -> one raw Int16[] per data segment, in file order
// raw.Tail       -> the optional trailing INFO block, if present

This lets callers handle files with a metadata schema BinfileReader doesn't
recognize by parsing RawJson themselves, instead of getting an exception with no
workaround.

BinfileReader itself is completely untouched — this is a purely additive,
opt-in alternative for the "I have a file this library can't parse" case, not a
replacement.

Testing

  • 6 new tests in RawContainerReaderTests.cs: the AKIP-4122/7 fixture (single
    segment, no tail), the existing OWON fixture, a synthetic multi-segment +
    INFO-tail case (to exercise segment-boundary/tail detection that no single real
    fixture covers), and the three existing error paths (invalid header, invalid JSON
    size, stream not at position 0).
  • Added testfiles/akip.bin, a real capture from an AKIP-4122/7 (firmware V7.6.0),
    as a small (~20 KB) fixture.
  • All 27 tests (21 existing + 6 new) pass.

Docs

Added a short new README section ("Reading files from other scopes on the same
platform") documenting RawContainerReader, its motivation, and a usage example, right
before the existing TestApp section. No existing README content was changed.

…ON's JSON schema

BinfileReader throws on capture files whose JSON metadata doesn't match the
OWON/Hanmatek schema it expects. An AKIP-4122/7 capture, for example, uses the
same SPBXDS container but a different JSON layout (lowercase `channel` array,
Display_Switch/Reference_Zero/Voltage_Rate instead of
CHANNEL/DISPLAY/Current_Ratio/Current_Rate) and includes a trailing comma
before the array's closing bracket, which makes System.Text.Json throw:

  System.Text.Json.JsonException: The JSON array contains a trailing comma at
  the end which is not supported in this mode. Change the reader options.

RawContainerReader parses only the vendor-agnostic parts of the container --
magic header, JSON length, JSON text (untouched, no assumptions about its
schema), one Int16[] per data segment, and the optional trailing INFO block --
so callers can interpret non-OWON metadata themselves instead of hitting this
exception. BinfileReader is untouched; this is purely additive.

Includes a real AKIP-4122/7 capture as a test fixture and tests covering both
the AKIP and OWON containers, plus the existing error paths.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant