FastLED 3.9.15
Loading...
Searching...
No Matches
asset.h File Reference

Detailed Description

First-class asset handles for sketches that live under <sketch>/data/.

This header is part of the v1 asset pipeline (FastLED issue #2284).

Usage from a sketch:

fl::UIAudio audio("Audio", FL_ASSET("data/track.mp3"));
fl::UIAudio audio("Audio Input")
#define FL_ASSET(LITERAL_PATH)
Preferred entry point: rejects .. at compile time via FL_STATIC_ASSERT.
Definition asset.h:137

At build time, fbuild scans <sketch>/data/ for *.lnk files containing URLs and emits a manifest. At runtime:

  • On WASM, the manifest is consulted to turn the relative path into the URL the browser should fetch.
  • On host/stub, the asset resolves to the file on disk — or, if the raw file is missing but a *.lnk exists alongside, to the URL from the .lnk (same fallback as WASM).

v1 scope: WASM and host/stub only. ESP32 LittleFS / SD-card resolution is future work and intentionally omitted.

Compile-time validation: FL_ASSET("data/../foo.mp3") and any path containing .. segments is rejected via FL_STATIC_ASSERT. The normalized path is stored verbatim; runtime resolution never walks parent directories.

Definition in file asset.h.

#include "fl/stl/int.h"
#include "fl/stl/noexcept.h"
#include "fl/stl/static_assert.h"
#include "fl/stl/string.h"
#include "fl/stl/string_view.h"
#include "fl/stl/url.h"
+ Include dependency graph for asset.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  fl::asset_ref
 Opaque handle to a sketch-local asset. More...
 

Namespaces

namespace  fl
 Base definition for an LED controller.
 
namespace  fl::asset_detail
 

Macros

#define FL_ASSET(LITERAL_PATH)
 Preferred entry point: rejects .. at compile time via FL_STATIC_ASSERT.
 

Functions

constexpr asset_ref fl::asset (const char *path) FL_NOEXCEPT
 Construct an asset handle from a relative sketch path at runtime.
 
constexpr fl::size fl::asset_detail::clen (const char *s, fl::size n=0) FL_NOEXCEPT
 Compile-time length of a null-terminated C string.
 
constexpr bool fl::asset_detail::is_parent_at (const char *p, fl::size i) FL_NOEXCEPT
 Compile-time check: does position i in p start a ".." segment?
 
constexpr bool fl::asset_detail::path_has_parent_segment (const char *p) FL_NOEXCEPT
 Compile-time check: returns true if the string contains a ".." segment.
 
constexpr bool fl::asset_detail::path_has_parent_segment_at (const char *p, fl::size i) FL_NOEXCEPT
 Recursive constexpr walk looking for any ".." segment.
 
void fl::register_asset (fl::string_view path, const fl::url &u) FL_NOEXCEPT
 Public helper: plug an asset mapping at runtime.
 
fl::url fl::resolve_asset (const asset_ref &a) FL_NOEXCEPT
 Resolve an asset handle to a URL (or local file path) at runtime.