FastLED 3.9.15
Loading...
Searching...
No Matches

◆ parse_lnk_with_metadata()

LnkMetadata fl::parse_lnk_with_metadata ( fl::string_view content)
inline

Parse a .lnk file into URL + metadata (forward-compat).

Accepts the same format as parse_lnk() and additionally scans non-comment key=value lines that follow the primary URL. Recognized keys:

v1: the returned metadata is parsed but NOT enforced by the runtime. sha256 is not verified and fallback is not retried. These fields are reserved for future integrity/retry features so existing .lnk files remain valid when richer behavior lands.

Definition at line 325 of file url.h.

325 {
326 LnkMetadata out;
327 bool gotPrimary = false;
328 fl::size pos = 0;
329 while (pos < content.size()) {
330 fl::size eol = content.find('\n', pos);
331 fl::size lineEnd = (eol == fl::string_view::npos) ? content.size() : eol;
332 fl::string_view line = content.substr(pos, lineEnd - pos);
333 pos = (eol == fl::string_view::npos) ? content.size() : eol + 1;
334
335 if (!line.empty() && line[line.size() - 1] == '\r') {
336 line = line.substr(0, line.size() - 1);
337 }
338
339 fl::size s = 0;
340 while (s < line.size() &&
341 (line[s] == ' ' || line[s] == '\t')) {
342 ++s;
343 }
344 fl::size e = line.size();
345 while (e > s &&
346 (line[e - 1] == ' ' || line[e - 1] == '\t')) {
347 --e;
348 }
349 line = line.substr(s, e - s);
350
351 if (line.empty() || line[0] == '#') {
352 continue;
353 }
354
355 if (!gotPrimary) {
356 out.primary = url(line);
357 gotPrimary = true;
358 continue;
359 }
360
361 // Subsequent lines: look for "key=value" metadata.
362 fl::size eq = line.find('=');
363 if (eq == fl::string_view::npos) {
364 // Unknown non-kv line, ignore (forward-compat).
365 continue;
366 }
367 fl::string_view key = line.substr(0, eq);
368 fl::string_view value = line.substr(eq + 1);
369 if (key == "sha256") {
370 out.sha256 = fl::string(value.data(), value.size());
371 } else if (key == "fallback") {
372 out.fallback = url(value);
373 }
374 // else: unknown key, ignore.
375 }
376 return out;
377}
uint8_t pos
Definition Blur.ino:11
constexpr bool empty() const FL_NOEXCEPT
static constexpr fl::size npos
Definition string_view.h:35
constexpr fl::size size() const FL_NOEXCEPT
Definition string_view.h:99
fl::size find(char ch, fl::size pos=0) const FL_NOEXCEPT
string_view substr(fl::size pos=0, fl::size count=npos) const FL_NOEXCEPT
Definition url.h:15
constexpr int type_rank< T >::value
fl::url primary
First non-comment URL in the file.
Definition url.h:253
fl::url fallback
Mirror URL used if primary fails (reserved).
Definition url.h:255
fl::string sha256
Hex-encoded sha256 of the expected asset (reserved).
Definition url.h:254
Metadata extracted from a .lnk asset link file.
Definition url.h:252

References fl::string_view::empty(), fl::LnkMetadata::fallback, fl::string_view::find(), FL_NOEXCEPT, fl::string_view::npos, pos, fl::LnkMetadata::primary, fl::LnkMetadata::sha256, fl::string_view::size(), fl::string_view::substr(), and type_rank< T >::value.

+ Here is the call graph for this function: