Skip to content

feat(fl/fled): Fled value type with PIMPL + 3 load factories (#3311 PR1) - #3323

Merged
zackees merged 4 commits into
masterfrom
feat/fled-skeleton-3311
Jun 20, 2026
Merged

zackees merged 4 commits into
masterfrom
feat/fled-skeleton-3311

Conversation

@zackees

@zackees zackees commented Jun 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Stand up the new src/fl/fled/ subsystem with the fl::Fled bundle value type. PR1 of #3311 — strictly the bare skeleton; typed accessors land in PR2, CFastLED::load + FledDispatcher land in PR5.

Per the issue's directive: fl::Fled is a passive value — constructing it and reading from it touches zero global state (no controllers registered, no EngineEvents broadcast, no scheduler hook).

What this PR adds

  • fl::Fled — PIMPL value, cheap to copy, default-constructs to null state (operator bool == false).
  • Three load factories:
    • Fled::load(FileSystem&, path) — reads + owns
    • Fled::loadFromStatic(span<const u8>) — zero-copy over PROGMEM / .rodata
    • Fled::loadFromVector(vector<u8>&&) — move-in
  • Raw accessors:
    • json() — parsed envelope (safe const-ref-to-static-empty for null Fled)
    • blob("frame_payload", &n) (alias "payload") — post-JSON bytes via aliasing shared_ptr, lifetime tied to impl
  • Introspection: version() (header byte; 0 for null) + sectionCount() (top-level JSON keys; 0 for null)
  • Strict v1 header validation — rejects bad magic, version != 1, oversized json_length, malformed JSON. All failures yield a null Fled with no FL_ERROR noise (preserves the default-constructible contract).

Out of scope (later PRs)

  • video() / screenMap() / channels() / script() typed accessors → PR2
  • FileSystem::loadFled sugar + littleFs/wasm/host factories → PR3
  • Video::fromFled / ScreenMap::fromFled / MultiChannelConfig::fromFled → PR4
  • CFastLED::load / loadChannels / loadScreenMap + FledDispatcher → PR5
  • CFastLED::enableWasm / enableMicroPy → PR6
  • FxSdCard.ino migration → PR7

Build plumbing

  • New: src/fl/build/fl.fled+.cpp — the rglob-discovered TU that pulls in the fl/fled/ unity build (mirrors the per-subdir pattern under src/fl/build/).
  • Edit: src/fl/_build.cpp.hpp — inserted #include "fl/fled/_build.cpp.hpp" in alphabetical order between fl/control/ and fl/font/.

Test plan

  • bash test fled --debug — green (1/1 DLL passed; 9 cases inside)
  • bash lint — green (cpp_linting, python_pipeline, javascript_linting, meson_linting all pass)
  • CI matrix on this PR
  • Manual: cover default null + both positive load paths + shared-copy semantics + 4 negative header paths + malformed JSON

Refs #3311

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced fl::Fled for parsing and accessing .fled v1 containers from a filesystem path, static bytes, or owned byte vectors.
    • Provides non-throwing loading plus JSON envelope access, version metadata, section counting, and payload retrieval by section name with null-safe behavior when parsing fails.
  • Tests

    • Added unit tests covering valid parsing, negative validation cases, accessor correctness, default/empty behavior, and preservation of parsed state across copies.

…on/blob accessors (#3311 PR1)

Stand up the new src/fl/fled/ subsystem with the fl::Fled bundle value
type. This is PR1 of #3311 — strictly the bare skeleton:

- fl::Fled — PIMPL value, cheap to copy, default-constructs to null state.
- Load factories: load(FileSystem&, path), loadFromStatic(span) [zero-copy],
  loadFromVector(vec&&) [move-in].
- Raw accessors: json() returns the parsed envelope; blob("frame_payload",
  &n) (alias "payload") returns the post-JSON bytes via aliasing shared_ptr.
- Introspection: version() (header byte) + sectionCount() (top-level JSON
  keys).
- Strict v1 header validation: rejects bad magic, version != 1, oversized
  json_length, malformed JSON envelope. All failures yield a null Fled
  (operator bool == false) — no FL_ERROR noise.

Typed accessors (video / screenMap / channels) and the FledScript type
land in PR2. CFastLED::load + FledDispatcher land in PR5.

Build plumbing: added src/fl/build/fl.fled+.cpp (the rglob-discovered
unity TU that pulls in fl/fled/) and inserted fl/fled/_build.cpp.hpp in
alphabetical order between fl/control/ and fl/font/ in src/fl/_build.cpp.hpp.

Tests: 9 cases in tests/fl/fled/fled.cpp — default null state, both
positive load paths (static + vector), shared-copy semantics, and four
negative header paths (too short, wrong magic, wrong version, oversize
json_length) plus malformed JSON.

Refs #3311

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 20, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7e05902e-df9c-464a-82e7-895fd4b88a9f

📥 Commits

Reviewing files that changed from the base of the PR and between 4d32a4a and 5ab8c88.

📒 Files selected for processing (1)
  • ci/lint_cpp_rs/src/checkers/unity_build.rs

📝 Walkthrough

Walkthrough

Introduces fl::Fled, a new PIMPL-based value-type handle for parsing .fled v1 binary containers. The implementation adds a public header declaring three non-throwing factory loaders, a private FledImpl storage class with owned/borrowed byte modes, a parsing implementation file, unity-build wiring files, and a comprehensive unit test suite.

Changes

fl::Fled subsystem

Layer / File(s) Summary
Public API and PIMPL storage contract
src/fl/fled/fled.h, src/fl/fled/fled_impl.hpp
fl::Fled is declared as a PIMPL value handle with three static factory loaders (load, loadFromStatic, loadFromVector), operator bool, json/blob/version/sectionCount accessors, and all-FL_NO_EXCEPT markers. fl::FledImpl defines owned-vs-static byte storage, an Ownership enum, and bytes/totalLen/payloadLen/versionByte/payloadOffset/envelope accessors.
Binary parsing, factories, and observers
src/fl/fled/fled.cpp.hpp
Anonymous-namespace helpers validate the 4-byte FLED magic, version byte, 32-bit little-endian JSON length (max 1 MiB), and strictly parse the JSON envelope. Three factory methods share that parser and return a null Fled on failure or construct FledImpl on success. Observers are null-safe: blob() restricts retrieval to "frame_payload"/"payload" names and returns an aliasing shared_ptr into the backing buffer.
Unity-build wiring and configuration
src/fl/fled/_build.cpp.hpp, src/fl/build/fl.fled+.cpp, src/fl/_build.cpp.hpp, ci/lint_cpp_rs/src/checkers/unity_build.rs
fl/fled/_build.cpp.hpp includes fled.cpp.hpp; fl.fled+.cpp is a standalone unity-build entry point with platform/arduino setup; fl/_build.cpp.hpp gains one line pulling the fled module into the top-level build. The CI lint checker's expected unity build files list is updated to include fl.fled+.cpp.
Unit tests
tests/fl/fled/fled.cpp
A buildValidBundle helper constructs in-memory .fled byte buffers. Tests cover: null/default state, happy-path loadFromStatic/loadFromVector (version, sectionCount, JSON access, blob length and boundary bytes, unknown-section null return), cheap-copy validity, and rejection of too-short buffers, wrong magic, bad version, empty span, oversized JSON length, and garbage JSON.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Fled
  participant parseHeaderAndJSON
  participant FledImpl
  participant FileSystem

  rect rgba(100, 149, 237, 0.5)
    note over Caller,FileSystem: Load from filesystem path
    Caller->>Fled: load(fs, path)
    Fled->>FileSystem: openRead(path) → vector~u8~
    Fled->>parseHeaderAndJSON: validate magic/version/json_length, parse JSON
    parseHeaderAndJSON-->>Fled: failure → empty Fled{}
    parseHeaderAndJSON-->>Fled: success → version, payloadOffset, envelope
    Fled->>FledImpl: construct(moved vector, version, payloadOffset, envelope)
    Fled-->>Caller: truthy Fled handle
  end

  rect rgba(144, 238, 144, 0.5)
    note over Caller,FledImpl: Access parsed sections
    Caller->>Fled: blob("frame_payload", &outLen)
    Fled->>FledImpl: payloadLen(), bytes(), payloadOffset()
    Fled-->>Caller: aliasing shared_ptr pinning FledImpl, outLen set
    Caller->>Fled: json()
    Fled->>FledImpl: envelope()
    Fled-->>Caller: const fl::json& envelope
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#2335: Both PRs update src/fl/_build.cpp.hpp to wire new modules into the top-level unity build; this PR adds fl/fled/_build.cpp.hpp while the other adds fl/asset.cpp.hpp.

Poem

🐇 A bundle called FLED hops into the tree,
Four magic bytes check, then JSON runs free,
The rabbit inspects each frame payload byte,
Shared pointers alias the buffer just right,
No throw, no fuss—the tests all agree! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: introducing the fl::Fled value type with PIMPL pattern and three load factories, directly matching the PR's primary objective.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/fled-skeleton-3311

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/fl/fled/_build.cpp.hpp (1)

1-1: 💤 Low value

Minor: Fix Doxygen comment to match filename.

The @file comment references _build.hpp, but the actual filename is _build.cpp.hpp.

-/// `@file` _build.hpp
+/// `@file` _build.cpp.hpp
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/fl/fled/_build.cpp.hpp` at line 1, The Doxygen `@file` comment at the
beginning of the file incorrectly references _build.hpp when the actual filename
is _build.cpp.hpp. Update the `@file` directive to match the correct filename
_build.cpp.hpp to ensure the Doxygen documentation properly reflects the actual
file being documented.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/fl/fled/fled_impl.h`:
- Around line 20-53: The file `fled_impl.h` contains inline function definitions
including the FledImpl constructor overloads (lines 20-28 and 31-39) and member
functions like bytes(), totalLen(), versionByte(), payloadOffset(),
payloadLen(), and envelope() (lines 41-53), which violates the guideline that
`.h` files should only contain declarations. Rename this file from `fled_impl.h`
to `fled_impl.hpp` or `fled_impl.impl.hpp` to properly signal that it contains
implementation details and inline function definitions. Update any include
statements in other files that reference this header to use the new file name.

In `@src/fl/fled/fled.cpp.hpp`:
- Around line 47-58: The code performs a narrowing cast from fl::u32 jsonLen to
fl::size jsonLenSz before validating against kMaxJsonBytes, which can cause
wraparound on platforms where fl::size is smaller than u32. To fix this, check
if jsonLen (the u32 value) exceeds kMaxJsonBytes before casting it to jsonLenSz.
This ensures the full 32-bit value is validated against the size limit before
any potential truncation occurs during the narrowing cast.

In `@tests/fl/fled/fled.cpp`:
- Around line 2-3: Replace all Unicode em dashes (—) in the comments throughout
the fled.cpp file with ASCII equivalents such as double hyphens (--) or commas,
to comply with the ASCII-only C++ source rule. This includes the comments on
lines 2, 23, 108, and 140 where em dashes currently appear. Scan through all
comments in the file to ensure no Unicode punctuation remains and all are
replaced with standard ASCII characters.

---

Nitpick comments:
In `@src/fl/fled/_build.cpp.hpp`:
- Line 1: The Doxygen `@file` comment at the beginning of the file incorrectly
references _build.hpp when the actual filename is _build.cpp.hpp. Update the
`@file` directive to match the correct filename _build.cpp.hpp to ensure the
Doxygen documentation properly reflects the actual file being documented.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1eac8ece-987a-4b25-b4e9-3595299eb39a

📥 Commits

Reviewing files that changed from the base of the PR and between 493e9a2 and 569fab1.

📒 Files selected for processing (7)
  • src/fl/_build.cpp.hpp
  • src/fl/build/fl.fled+.cpp
  • src/fl/fled/_build.cpp.hpp
  • src/fl/fled/fled.cpp.hpp
  • src/fl/fled/fled.h
  • src/fl/fled/fled_impl.h
  • tests/fl/fled/fled.cpp

Comment thread src/fl/fled/fled_impl.hpp Resolved
Comment thread src/fl/fled/fled.cpp.hpp Resolved
Comment thread tests/fl/fled/fled.cpp Resolved
zackees and others added 3 commits June 19, 2026 22:48
…t cases

Address PR review on #3323:
- H1: tighten blob() doc-comment + impl comment to make explicit that
  the aliasing shared_ptr pins FledImpl but does NOT extend the lifetime
  of bytes passed to loadFromStatic — the caller's span lifetime contract
  still applies.
- M2: add a test for version==0 (accidental-zero-init failure mode).
- M3: add a test for loadFromStatic(empty span).

Refs #3311 #3323

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
- Rename fled_impl.h -> fled_impl.hpp; the file contains inline ctors
  and member function definitions and per the repo guideline that
  belongs in a .hpp, not a .h.
- Move kMaxJsonBytes bound-check above the narrowing cast to fl::size,
  so oversized json_length values cannot wraparound on 16-bit targets
  (AVR has 16-bit size_t).
- Replace em-dashes with ASCII hyphens in the touched files per the
  repo's ASCII-only C++ source rule.
- Fix _build.cpp.hpp doxygen filename mismatch (was @file _build.hpp).

Refs #3311 #3323

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
The Rust-backed C++ linter (ci/lint_cpp_rs/src/checkers/unity_build.rs)
maintains a hard allowlist of expected src/fl/build/*+.cpp unity files.
CI rejected the new src/fl/build/fl.fled+.cpp introduced for the fl/fled/
subsystem because the file wasn't in that list. Add it (alphabetical
position between fl.codec+.cpp and fl.font+.cpp).

Refs #3311 #3323

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@zackees

zackees commented Jun 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai resolve

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
✅ Action performed

Comments resolved and changes approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant