Skip to content

refactor(fl/fled): focus on header/json/blob/objects + FledBuilder + full FLED_FORMAT.md spec coverage (#3311) - #3334

Merged
zackees merged 1 commit into
masterfrom
refactor/fled-restructure-3311
Jun 20, 2026
Merged

zackees merged 1 commit into
masterfrom
refactor/fled-restructure-3311

Conversation

@zackees

@zackees zackees commented Jun 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Per follow-up direction, the v1 fl/fled subsystem is restructured around four concrete responsibilities and nothing else:

  1. Header info — version(), pixelFormat(), bytesPerLed()
  2. JSON envelope — json(), sectionCount(), videoFps()
  3. Raw blob ranges — blob(\"frame_payload\", &n) for video bytes
  4. Fully constructed objects — screenMap(), channels() (stub)

Plus a new fl::fled::FledBuilder for imperative assembly: header + optional screenmap JSON + optional channels JSON + optional payload.

Removed entirely

  • CFastLED::load / loadChannels / loadScreenMap and their per-method TUs (src/fl/fled/load/, load_channels/, load_screen_map/ directories + matching src/fl/build/fl.fled.load*+.cpp wrappers + UNITY_EXPECTED_BUILD_FILES allowlist entries). These were half-baked stubs that contributed nothing real.
  • fl::FledScript, fl::ScriptKind — scripting types purged from code; the scripting roadmap stays only in src/fl/fled/*.md as future-v2 doc.
  • src/fl/fled/fwd.h — only existed for the now-deleted CFastLED methods.
  • Video::fromFled, ScreenMap::fromFled, MultiChannelConfig::fromFled — bidirectional forwarders did not belong on those types; removed along with the fl::Fled forward decls in fl/fx/video.h, fl/math/screenmap.h, fl/channels/config.h.
  • Fled::video(), Fled::script() — replaced by blob() + json() for video; script removed entirely.

Namespace + layout rule

  • fl::Fled (the public API type) stays at top-level fl::.
  • All auxiliary types and free functions live in fl::fled, with files under src/fl/fled/detail/.
    • fl::fled::FledImpl (PIMPL) moved to src/fl/fled/detail/fled_impl.hpp
    • fl::fled::ParsedHeader + parseHeaderAndEnvelope + sectionNameIsPayload in src/fl/fled/detail/parser.{h,cpp.hpp}
    • fl::fled::PixelFormat enum + bytesPerLed() in src/fl/fled/detail/pixel_format.{h,cpp.hpp}
    • fl::fled::FledBuilder in src/fl/fled/builder.{h,cpp.hpp}

fled.cpp.hpp is now a thin facade — parser internals were lifted out into fl::fled::parseHeaderAndEnvelope; the factories just call the free function and construct FledImpl.

FLED_FORMAT.md spec coverage (new)

  • All five v1 pixel formats (rgb8, gray8, rgba8, rgbw8, rgb565le) map to canonical bytes-per-LED.
  • Reserved formats (0x05–0xff) return 0 bpp so callers reject before reading frame bytes per spec.
  • frameCount(ledCount) implements frame_count = payload_bytes / (led_count * bytes_per_led).
  • videoFps(default=30) reads envelope video.fps with default fallback per the spec's "consumers may use an application default" clause.

Tests

  • tests/fl/fled/fled.cpp — kept + extended header/blob/screenMap cases (~20 cases)
  • tests/fl/fled/fled_format.cpp NEW — 17 cases walking FLED_FORMAT.md point-by-point: all five pixel formats × bytes-per-LED, frame-count derivation including truncation + reserved-format zero, video.fps reader with all fallback paths, envelope passthrough, screenMap parse from the spec's example envelope, led_count-driven frameCount
  • tests/fl/fled/fled_builder.cpp — 5 cases covering header-only / setVersion+pixelFormat / + screenmap json / + payload / end-to-end
  • tests/fl/fled/fled_filesystem.cpp — unchanged (MemoryFs mock integration test)
  • tests/fl/fled/fled_load.cpp, fled_from_fled.cpp — deleted (tested removed surface)

Test plan

  • bash test fled --debug — green
  • bash lint --cpp — green
  • CI matrix

Refs #3311

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Breaking Changes

    • Removed .fled bundle loading APIs (load, loadChannels, loadScreenMap) from FastLED
    • Removed video() and script() typed accessors from FLED bundles
    • Removed script support from FLED container format
  • New Features

    • Added FledBuilder for programmatic v1 FLED bundle construction
    • Added metadata accessors: pixelFormat(), bytesPerLed(), payloadBytes(), frameCount(), videoFps()
  • Tests

    • Expanded FLED format and builder test coverage

…er + full FLED_FORMAT.md spec coverage (#3311)

Per follow-up direction, the v1 fl/fled subsystem is restructured around
four concrete responsibilities and nothing else:

1. Header info  - version(), pixelFormat(), bytesPerLed()
2. JSON envelope - json(), sectionCount(), videoFps()
3. Raw blob ranges - blob("frame_payload", &n) for video bytes
4. Fully constructed objects - screenMap(), channels() (stub)

Plus a new FledBuilder for imperative assembly of a bundle from header
+ optional screenmap JSON + optional channels JSON + optional payload.

Removals (gone entirely):
- CFastLED::load / loadChannels / loadScreenMap and their per-method TUs
  (src/fl/fled/load/, load_channels/, load_screen_map/ directories +
  the matching src/fl/build/fl.fled.load*+.cpp wrappers + UNITY allowlist
  entries). These were half-baked stubs that contributed nothing real.
- fl::FledScript, fl::ScriptKind - scripting types purged from code;
  the scripting roadmap stays only in src/fl/fled/*.md as future-v2 doc.
- src/fl/fled/fwd.h - only existed for the now-deleted CFastLED methods.
- Video::fromFled, ScreenMap::fromFled, MultiChannelConfig::fromFled -
  bidirectional forwarders did not belong on those types; removed along
  with the fl::Fled forward decls in fl/fx/video.h, fl/math/screenmap.h,
  fl/channels/config.h.
- Fled::video(), Fled::script() accessors - replaced by blob() + json()
  for video; script removed entirely.

Namespace + layout rule:
- fl::Fled (the public API type) stays at top-level fl::.
- All auxiliary types and free functions live in fl::fled, with files
  under src/fl/fled/detail/.
  - fl::fled::FledImpl (PIMPL) moved to src/fl/fled/detail/fled_impl.hpp
  - fl::fled::ParsedHeader + parseHeaderAndEnvelope + sectionNameIsPayload
    in src/fl/fled/detail/parser.{h,cpp.hpp}
  - fl::fled::PixelFormat enum + bytesPerLed() in
    src/fl/fled/detail/pixel_format.{h,cpp.hpp}
  - fl::fled::FledBuilder in src/fl/fled/builder.{h,cpp.hpp}

fled.cpp.hpp is now a thin facade - the parser internals were lifted
out into fl::fled::parseHeaderAndEnvelope; the factories just call into
that free function and construct FledImpl.

FLED_FORMAT.md spec coverage (new):
- All five v1 pixel formats (0x00 rgb8, 0x01 gray8, 0x02 rgba8,
  0x03 rgbw8, 0x04 rgb565le) map to their canonical bytes-per-LED.
- Reserved pixel formats (0x05..0xff) return 0 bpp so callers can
  reject before reading frame bytes per spec.
- frameCount(ledCount) implements the spec's
  frame_count = payload_bytes / (led_count * bytes_per_led) formula.
- videoFps(default=30) reads envelope.video.fps with a default fallback
  per the spec's "consumers may use an application default" clause.

Tests (tests/fl/fled/):
- fled.cpp - keep + extend the existing header/blob/screenMap cases.
- fled_format.cpp NEW - 17 cases walking the FLED_FORMAT.md spec
  point-by-point: all five pixel formats x bytes-per-LED, frame-count
  derivation including truncation + reserved-format zero, video.fps
  reader with all fallback paths, envelope passthrough, screenMap
  parse from the spec's example envelope, led_count-driven frameCount.
- fled_builder.cpp - 5 cases covering header-only / setVersion+pixel
  fmt / + screenmap json / + payload / end-to-end.
- fled_filesystem.cpp - unchanged (MemoryFs mock integration test).
- fled_load.cpp, fled_from_fled.cpp - deleted (tested the removed
  surface).

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

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Removes CFastLED::load/loadChannels/loadScreenMap entry points, deletes fromFled static factories from ScreenMap/Video/MultiChannelConfig, and removes FledScript/fwd.h. Introduces detail/parser and detail/pixel_format modules, extends FledImpl with pixel format storage, revises Fled's public API with new header/payload accessors, and adds a new FledBuilder for in-process bundle construction.

Changes

Fled subsystem refactor

Layer / File(s) Summary
Remove CFastLED load APIs, fromFled factories, and unity-build files
src/FastLED.h, src/fl/build/fl.fled.load*+.cpp, src/fl/channels/config.h, src/fl/math/screenmap.h, src/fl/fx/video.h, src/fl/fled/fled_script.h, src/fl/fled/fwd.h, src/fl/fled/load*/..., ci/lint_cpp_rs/src/checkers/unity_build.rs
Removes CFastLED::load, loadChannels, loadScreenMap declarations, their unity-build .cpp entry-point files and _build.cpp.hpp aggregates, the fromFled static factories on ScreenMap/Video/MultiChannelConfig, and deletes FledScript and fwd.h. Updates the unity-build lint allowlist accordingly.
Add detail/parser and detail/pixel_format modules, update FledImpl
src/fl/fled/detail/parser.h, src/fl/fled/detail/parser.cpp.hpp, src/fl/fled/detail/pixel_format.h, src/fl/fled/detail/pixel_format.cpp.hpp, src/fl/fled/detail/_build.cpp.hpp, src/fl/fled/detail/fled_impl.hpp
Introduces PixelFormat enum and bytesPerLed lookup; adds ParsedHeader struct with parseHeaderAndEnvelope and sectionNameIsPayload free functions; extends FledImpl constructors to take and store pixelFormatByte with a new accessor; adds the detail unity-build aggregate.
Revise Fled public API and implementation
src/fl/fled/fled.h, src/fl/fled/fled.cpp.hpp
Adds pixelFormat, bytesPerLed, payloadBytes, frameCount, videoFps to fl::Fled; removes video() and script(); rewrites loadFromStatic/loadFromVector to delegate to parseHeaderAndEnvelope; implements new accessors with null-guard pattern; removes Video/ScreenMap/MultiChannelConfig fromFled forwarding implementations.
Add FledBuilder
src/fl/fled/builder.h, src/fl/fled/builder.cpp.hpp, src/fl/fled/_build.cpp.hpp
Introduces fl::fled::FledBuilder with fluent setters for version, pixel format, screen map JSON, channels JSON, and payload; build() serializes the 12-byte header plus JSON envelope plus payload and returns a Fled via loadFromVector. Updates the fl/fled unity-build aggregate to include the new builder and detail units.
Update and add tests
tests/fl/fled/fled.cpp, tests/fl/fled/fled_builder.cpp, tests/fl/fled/fled_format.cpp, tests/fl/fled/fled_from_fled.cpp (deleted), tests/fl/fled/fled_load.cpp (deleted)
Updates fled.cpp for pixelFormat round-trips and reorganized typed-accessor stubs. Adds fled_builder.cpp covering FledBuilder end-to-end. Adds fled_format.cpp verifying bytesPerLed, frameCount, videoFps, JSON envelope survival, ScreenMap parsing, and frame payload access. Removes test files for deleted APIs.

Sequence Diagram(s)

sequenceDiagram
  rect rgba(135, 180, 220, 0.5)
    Note over Client,FledBuilder: Build path (new)
    Client->>FledBuilder: setVersion(1), setPixelFormat(0x01), setScreenMapJson(...), setPayload(bytes)
    FledBuilder->>FledBuilder: buildJsonEnvelope(screenMapJson, channelsJson)
    FledBuilder->>FledBuilder: serialize 12-byte header + JSON + payload → buf
    FledBuilder->>Fled: loadFromVector(move(buf))
  end

  rect rgba(180, 220, 135, 0.5)
    Note over Fled,FledImpl: Parse path (revised)
    Fled->>parseHeaderAndEnvelope: data, len
    parseHeaderAndEnvelope->>parseHeaderAndEnvelope: validate magic, version, JSON length bounds
    parseHeaderAndEnvelope-->>Fled: ParsedHeader{version, pixelFormat, payloadOffset}, envelope JSON
    Fled->>FledImpl: construct(owned, version, pixelFormat, payloadOffset, envelope)
    Fled-->>Client: Fled handle with pixelFormat(), bytesPerLed(), frameCount(), videoFps(), screenMap(), blob()
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related issues

Possibly related PRs

  • FastLED/FastLED#3323: This PR is a direct continuation of that one, revising the same fled.h/fled.cpp.hpp and unity-build integration paths introduced there.
  • FastLED/FastLED#3328: This PR removes the fromFled bidirectional factories and deletes tests/fl/fled/fled_from_fled.cpp, directly undoing APIs that were added in that PR.
  • FastLED/FastLED#3330: This PR removes CFastLED::load/loadChannels/loadScreenMap and their unity-build .cpp files — targeting the same additions introduced in that PR.

Poem

🐇 Hop hop, the old load() is gone,
A Builder hops in right at dawn,
parseHeaderAndEnvelope leads the way,
PixelFormat joins the fray!
Twelve bytes of magic, JSON neat —
The .fled format is now complete! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.93% 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 directly and specifically summarizes the main change: refactoring the fl/fled subsystem to focus on core responsibilities (header/json/blob/objects) plus a new FledBuilder and comprehensive spec coverage.
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 refactor/fled-restructure-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.

@zackees
zackees merged commit a6c8558 into master Jun 20, 2026
7 of 10 checks passed
@zackees
zackees deleted the refactor/fled-restructure-3311 branch June 20, 2026 09:26
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 20, 2026
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