Skip to content

feat: serialize CRGB buffers as JSON - #3922

Merged
zackees merged 1 commit into
masterfrom
feat/1008-crgb-json
Aug 20, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/1008-crgb-json

Conversation

@zackees

@zackees zackees commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Adds opt-in, versioned JSON persistence helpers for CRGB pixel buffers. Encoding is fallible and validates the completed document; decoding strictly validates version, count, channel types/ranges, and leaves the destination unchanged on failure. Includes focused tests and an ESP32 LittleFS cookbook recipe with validated temporary-file writes.

Validation:

  • bash test crgb_json
  • bash test crgb_json --debug
  • bash test --clean --cpp (281/281 unit, 84/84 examples)
  • bash lint
  • clud-review: clean

Closes #1008

Summary by CodeRabbit

  • New Features

    • Added JSON serialization and restoration for CRGB pixel arrays.
    • Added validation for data versions, pixel counts, RGB channels, and malformed input.
    • Added a cookbook recipe demonstrating safe save and restore workflows using LittleFS.
  • Documentation

    • Added the pixel persistence recipe to the cookbook’s Common Recipes list.
  • Tests

    • Added coverage for round trips, invalid data, empty arrays, and protection against partial updates.

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Aug 20, 2026
@zackees
zackees merged commit da149b9 into master Aug 20, 2026
8 of 17 checks passed
@zackees
zackees deleted the feat/1008-crgb-json branch August 20, 2026 10:07
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Aug 20, 2026
@coderabbitai

coderabbitai Bot commented Aug 20, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 233dfb84-f72e-4d95-b2e4-b863ff6e7560

📥 Commits

Reviewing files that changed from the base of the PR and between 0117996 and fe943d8.

📒 Files selected for processing (6)
  • cookbook/README.md
  • cookbook/recipes/persist-crgb.md
  • src/fl/gfx/_build.cpp.hpp
  • src/fl/gfx/crgb_json.cpp.hpp
  • src/fl/gfx/crgb_json.h
  • tests/fl/gfx/crgb_json.cpp

📝 Walkthrough

Walkthrough

Added versioned JSON serialization and validated deserialization for CRGB spans. Integrated the implementation into the graphics build, added validation tests, and documented LittleFS save and restore usage.

Changes

CRGB JSON persistence

Layer / File(s) Summary
JSON API and validation
src/fl/gfx/crgb_json.h, src/fl/gfx/crgb_json.cpp.hpp, src/fl/gfx/_build.cpp.hpp
Adds crgbToJson and crgbFromJson. The implementation validates schema, versions, pixel counts, channel types, and channel ranges before modifying destination pixels.
Serialization and validation tests
tests/fl/gfx/crgb_json.cpp
Tests round trips, empty spans, malformed documents, invalid channels, pixel-count mismatches, and protection against partial writes.
Persistence recipe documentation
cookbook/recipes/persist-crgb.md, cookbook/README.md
Documents LittleFS persistence with temporary files, write verification, atomic rename, load-time validation, and storage guidance. Adds the recipe to the common recipes list.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Application
  participant crgbToJson
  participant LittleFS
  participant crgbFromJson
  participant CRGBArray

  Application->>crgbToJson: Serialize CRGB span
  crgbToJson-->>Application: Return version-1 JSON
  Application->>LittleFS: Write and atomically rename file
  Application->>LittleFS: Read persisted JSON
  LittleFS-->>Application: Return file contents
  Application->>crgbFromJson: Validate and decode JSON
  crgbFromJson->>CRGBArray: Update pixels after validation
Loading
✨ 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/1008-crgb-json

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.

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.

Saving/Loading a CRGB Array?

1 participant