Skip to content

feat(fl/fled): typed section accessors + FledScript passive type (#3311 PR2) - #3326

Merged
zackees merged 1 commit into
masterfrom
feat/fled-typed-accessors-3311
Jun 20, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/fled-typed-accessors-3311

Conversation

@zackees

@zackees zackees commented Jun 20, 2026 •

Copy link
Copy Markdown
Member

Summary

PR2 of #3311. Adds the four typed section accessors to fl::Fled plus the new fl::FledScript passive type. Only screenMap() has a real body in PR2; video/channels/script are stubs whose implementations land in later PRs once their supporting deserializers exist.

Stacked on #3323 (PR1). Until that merges, this PR's diff will show the PR1 commits too. After #3323 lands, this auto-cleans up.

Per #3311's directive: each accessor touches zero global state (no controller registration, no EngineEvents broadcast, no scheduler).

What this PR adds

New type — fl::FledScript (src/fl/fled/fled_script.h):

enum class ScriptKind : fl::u8 { Wasm, MicroPy };
struct FledScript {
    ScriptKind                   kind;
    fl::shared_ptr<const fl::u8> bytes;
    fl::size                     length;
};

New accessors on fl::Fled:

Accessor PR2 status Filled in by
video() stub returning nullptr PR4 (needs Video::fromBytes factory)
screenMap() implemented via ScreenMap::ParseJson on envelope's "map" key —
channels() stub returning nullptr PR5 (needs MultiChannelConfig JSON deserializer)
script() stub returning nullptr v2 bundle format (no script section in v1)

screenMap() returns the first segment for multi-strip bundles; a dedicated multi-segment accessor is a later refactor. All non-object / absent "map" cases return nullptr.

Tests (6 new cases)

  • screenMap() returns null on default-constructed Fled
  • screenMap() returns null when envelope has no "map" key
  • screenMap() returns null when "map" is an empty object
  • screenMap() parses a real strip1 ScreenMap to length=3 with correct coordinates
  • video()/channels()/script() are stubs returning nullptr for a valid bundle
  • video()/channels()/script() return null on null Fled

Test plan

  • bash test fled --debug — green (1/1 DLL passed; 15 cases inside)
  • bash lint --cpp — green
  • CI matrix on this PR (will rerun after PR1 merges and this rebases)

Refs #3311

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added bundle file parsing and loading from multiple sources (filesystem, byte spans, vectors).
    • Implemented JSON envelope and payload section access with validation for format integrity.
    • Introduced typed accessors for embedded resources including video, screen maps, channel configurations, and scripts.
    • Added version and section count queries for bundle inspection.

@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: 1948e74d-b500-4fe5-9dab-8e383b6d58e8

📥 Commits

Reviewing files that changed from the base of the PR and between 3347395 and a2c8fbf.

📒 Files selected for processing (4)
  • src/fl/fled/fled.cpp.hpp
  • src/fl/fled/fled.h
  • src/fl/fled/fled_script.h
  • tests/fl/fled/fled.cpp
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/fl/fled/fled_script.h
  • src/fl/fled/fled.h
  • tests/fl/fled/fled.cpp
  • src/fl/fled/fled.cpp.hpp

📝 Walkthrough

Walkthrough

Adds fl::Fled implementation in fled.cpp.hpp: header format parsing (magic FLDE, version 1, 32-bit JSON length), three load factories, blob() with aliasing shared_ptr, screenMap() via ScreenMap::ParseJson, stub video()/channels()/script(), and metadata accessors. Adds FledScript/ScriptKind types and a full unit test suite.

Changes

fl::Fled subsystem

Layer / File(s) Summary
Public API and FledScript type
src/fl/fled/fled.h, src/fl/fled/fled_script.h
Updates fl::Fled header documentation, forward declarations, and typed accessor declarations (video, screenMap, channels, script) with null-return contracts; adds the new fl::FledScript carrier struct and fl::ScriptKind enum (Wasm, MicroPy).
Format constants, header parsing, and load factories
src/fl/fled/fled.cpp.hpp
Defines file-scope constants (magic, version, header size, 1 MiB max JSON); implements parseHeaderAndEnvelope validating magic/version/bounds and parsing the JSON envelope; implements load(FileSystem&), loadFromStatic(span), and loadFromVector(vector&&), all delegating to the same parser and returning empty Fled on failure.
Accessors, blob, screenMap, and metadata
src/fl/fled/fled.cpp.hpp
Implements constructors, operator bool, json() with null-guard returning a static empty JSON, blob() using an aliasing shared_ptr to pin FledImpl, screenMap() that extracts and parses the envelope's "map" key via ScreenMap::ParseJson, stub video()/channels()/script() returning empty shared pointers, and version()/sectionCount() metadata accessors.
Unit tests
tests/fl/fled/fled.cpp
Adds in-memory .fled v1 buffer builders; tests null contract, loadFromStatic/loadFromVector success, copy semantics, blob() with primary and alias section names, negative parsing cases (wrong magic, wrong/zero version, too-short, oversized JSON length, malformed JSON), screenMap() with absent/empty/valid map envelopes, and stub accessor null returns.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#3323: Adds the core fl::Fled PIMPL implementation (header parsing, load factories, observers/accessors) in src/fl/fled/fled.cpp.hpp, directly overlapping with this PR's implementation layer.

Poem

🐇 Hop, hop, the .fled file lands,
With magic bytes held in my paws and hands.
JSON envelope parsed, version one is blessed,
screenMap() returns the map — all the rest: TODO-fest!
Tests green and crisp like a fresh morning clover,
The bundle is loaded — this rabbit says, "It's over!" 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.81% 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 clearly and specifically describes the main change: adding typed section accessors and introducing FledScript, which are the primary additions in this PR.
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-typed-accessors-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.

… PR2)

PR2 of #3311. Adds the four typed section accessors to fl::Fled plus the
new fl::FledScript passive type. Only screenMap() has a real body in
PR2; video/channels/script are stubs whose implementations land in
later PRs once their supporting deserializers exist.

New types:
- fl::FledScript (src/fl/fled/fled_script.h) - passive struct carrying
  ScriptKind enum (Wasm | MicroPy) + shared_ptr to bytes + length.

New accessors on fl::Fled:
- video()     -> shared_ptr<Video>              (STUB; PR4 fills in)
- screenMap() -> shared_ptr<ScreenMap>          (IMPLEMENTED)
- channels()  -> shared_ptr<MultiChannelConfig> (STUB; PR5 fills in)
- script()    -> shared_ptr<FledScript>         (STUB; v2 bundle work)

screenMap() reads the envelope's "map" key, serializes the envelope back
to JSON, and hands it to fl::ScreenMap::ParseJson. Multi-strip bundles
return only the first segment in PR2; a dedicated multi-segment
accessor is a later refactor. All non-object / absent "map" cases
return nullptr.

Each accessor handles the null-Fled case (mImpl == null -> nullptr).
Each accessor's contract: ZERO global side effects per #3311's directive.

Tests (6 new cases in tests/fl/fled/fled.cpp): null-Fled returns null
for every accessor, missing "map" key returns null, empty "map" returns
null, a real strip1 ScreenMap parses to length=3 with correct coords,
and the three stub accessors return nullptr for every valid bundle.

Refs #3311 (this is the second of seven planned PRs)

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

@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: 1

🤖 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_script.h`:
- Around line 14-18: The struct FledScript violates the project's member-field
naming convention. Rename all three member fields in the FledScript struct to
use the mCamelCase prefix as required by the coding guidelines. Change kind to
mKind, bytes to mBytes, and length to mLength. Ensure all references to these
fields throughout the codebase are also updated to use the new naming
convention.
🪄 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: cb51612c-67a2-462f-9d0b-3b5d9327ac43

📥 Commits

Reviewing files that changed from the base of the PR and between 45474b5 and 3347395.

📒 Files selected for processing (9)
  • ci/lint_cpp_rs/src/checkers/unity_build.rs
  • 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.hpp
  • src/fl/fled/fled_script.h
  • tests/fl/fled/fled.cpp

Comment thread src/fl/fled/fled_script.h Resolved
@zackees
zackees force-pushed the feat/fled-typed-accessors-3311 branch from 3347395 to a2c8fbf Compare June 20, 2026 06:27
@zackees

zackees commented Jun 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai re the FledScript field naming: declining. Per the existing convention in src/fl/channels/config.h, struct types use plain field names (pin, timing, encoder, dataPin, clockPin, etc.) rather than mCamelCase. The mCamelCase convention applies to private class members. FledScript is a passive POD struct and follows the same plain-field convention as ClocklessChipset / SpiChipsetConfig / ChannelConfig. Also matches the #3311 spec verbatim.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@zackees: Understood, thanks for the clarification. Plain field names are correct for passive POD structs in this codebase — mCamelCase is reserved for private class members. Withdrawing the suggestion.

( ˵ •̀ ᴗ - ˵ ) ✧


✏️ Learnings added
Learnt from: zackees
URL: https://github.com/FastLED/FastLED/pull/3326

Timestamp: 2026-06-20T06:41:01.860Z
Learning: In the FastLED codebase (FastLED/FastLED), passive POD structs use plain field names (e.g., `pin`, `timing`, `bytes`, `length`, `kind`) rather than `mCamelCase`. The `mCamelCase` convention applies only to private class members. Examples: `ClocklessChipset`, `SpiChipsetConfig`, `ChannelConfig` in `src/fl/channels/config.h`, and `fl::FledScript` in `src/fl/fled/fled_script.h`.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

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