Repository navigation
feat(fl/fled): Fled value type with PIMPL + 3 load factories (#3311 PR1) - #3323
Conversation
…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]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughIntroduces Changesfl::Fled subsystem
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
src/fl/fled/_build.cpp.hpp (1)
1-1: 💤 Low valueMinor: Fix Doxygen comment to match filename.
The
@filecomment 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
📒 Files selected for processing (7)
src/fl/_build.cpp.hppsrc/fl/build/fl.fled+.cppsrc/fl/fled/_build.cpp.hppsrc/fl/fled/fled.cpp.hppsrc/fl/fled/fled.hsrc/fl/fled/fled_impl.htests/fl/fled/fled.cpp
…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]>
|
@coderabbitai resolve |
✅ Action performedComments resolved and changes approved. |
Summary
Stand up the new
src/fl/fled/subsystem with thefl::Fledbundle value type. PR1 of #3311 — strictly the bare skeleton; typed accessors land in PR2,CFastLED::load+FledDispatcherland in PR5.Per the issue's directive:
fl::Fledis a passive value — constructing it and reading from it touches zero global state (no controllers registered, noEngineEventsbroadcast, no scheduler hook).What this PR adds
fl::Fled— PIMPL value, cheap to copy, default-constructs to null state (operator bool== false).Fled::load(FileSystem&, path)— reads + ownsFled::loadFromStatic(span<const u8>)— zero-copy over PROGMEM /.rodataFled::loadFromVector(vector<u8>&&)— move-injson()— parsed envelope (safe const-ref-to-static-empty for null Fled)blob("frame_payload", &n)(alias"payload") — post-JSON bytes via aliasingshared_ptr, lifetime tied to implversion()(header byte; 0 for null) +sectionCount()(top-level JSON keys; 0 for null)version != 1, oversizedjson_length, malformed JSON. All failures yield a null Fled with noFL_ERRORnoise (preserves the default-constructible contract).Out of scope (later PRs)
video()/screenMap()/channels()/script()typed accessors → PR2FileSystem::loadFledsugar +littleFs/wasm/hostfactories → PR3Video::fromFled/ScreenMap::fromFled/MultiChannelConfig::fromFled→ PR4CFastLED::load/loadChannels/loadScreenMap+FledDispatcher→ PR5CFastLED::enableWasm/enableMicroPy→ PR6FxSdCard.inomigration → PR7Build plumbing
src/fl/build/fl.fled+.cpp— the rglob-discovered TU that pulls in thefl/fled/unity build (mirrors the per-subdir pattern undersrc/fl/build/).src/fl/_build.cpp.hpp— inserted#include "fl/fled/_build.cpp.hpp"in alphabetical order betweenfl/control/andfl/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)Refs #3311
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
fl::Fledfor parsing and accessing .fled v1 containers from a filesystem path, static bytes, or owned byte vectors.Tests