FastLED 3.10.6
Loading...
Searching...
No Matches
json_dispatch.h
Go to the documentation of this file.
1#pragma once
2
3// json_dispatch: type-erased core helpers for JSON-to-primitive conversion.
4//
5// Legacy `fl::detail::JsonToIntegerVisitor<T>` / `JsonToFloatVisitor<T>` /
6// `JsonToBoolVisitor` / `JsonToStringVisitor` (formerly in
7// `fl/remote/rpc/json_visitors.h`) each contained ~10 `operator()`
8// overloads (one per `json_value::variant_t` alternative). When invoked
9// via `data.visit(visitor)`, the variant emitted a `visit_fn<T, Visitor>`
10// thunk per (alternative × visitor) pair, plus the per-T body fan-out for
11// the templated visitors -- the audit in #3235 catalogued ~2-3 KB of
12// visitor codegen on LPC845.
13//
14// This dispatch layer collapses that per-(visitor × alternative)
15// explosion to **one** shared non-template body per output type. The
16// thin templated `JsonToType<T>::convert` (in `json_to_type.h`) calls
17// the appropriate core, gets back the canonical type
18// (`i64` / `bool` / `float` / `string`) plus a `TypeConversionResult`,
19// and applies per-T narrowing + range checking. The per-(T × alternative)
20// thunk explosion is gone, which is why the visitor classes themselves
21// were deleted in #3251 (no remaining callers).
22//
23// `FL_NO_INLINE` on the implementations is load-bearing under LTO --
24// without it the compiler inlines the body back at each call site,
25// defeating dedup.
26//
27// See FastLED #3247 / #3244 Tier 2E Phase 2, plus #3251 / Tier 3I dead-code
28// removal of the formerly-templated visitor classes.
29
30#include "fl/remote/rpc/type_conversion_result.h" // IWYU pragma: keep
31#include "fl/stl/int.h"
32#include "fl/stl/compiler_control.h" // FL_NO_INLINE
33#include "fl/stl/noexcept.h"
34
35namespace fl {
36
37struct json_value;
38
39namespace detail {
40
41// Each core returns the converted result in `out_value` and emits any
42// warnings / errors via the returned `TypeConversionResult`. Caller is
43// responsible for applying per-T narrowing on the result (e.g. casting
44// the returned `i64` to `int8_t` with overflow detection).
45//
46// All four cores switch over `val.data.tag()` and read the active
47// alternative via `data.template ptr<T>()` -- no `data.visit(visitor)`
48// call, no `visit_fn<T, Visitor>` thunk instantiation.
49
51TypeConversionResult json_convert_to_i64_core(const json_value& val,
52 fl::i64* out_value) FL_NO_EXCEPT;
53
55TypeConversionResult json_convert_to_bool_core(const json_value& val,
56 bool* out_value) FL_NO_EXCEPT;
57
59TypeConversionResult json_convert_to_float_core(const json_value& val,
60 float* out_value) FL_NO_EXCEPT;
61
63TypeConversionResult json_convert_to_string_core(const json_value& val,
64 fl::string* out_value) FL_NO_EXCEPT;
65
66} // namespace detail
67} // namespace fl
#define FL_NO_INLINE
FL_NO_INLINE TypeConversionResult json_convert_to_i64_core(const json_value &val, fl::i64 *out_value) FL_NO_EXCEPT
FL_NO_INLINE TypeConversionResult json_convert_to_float_core(const json_value &val, float *out_value) FL_NO_EXCEPT
FL_NO_INLINE TypeConversionResult json_convert_to_bool_core(const json_value &val, bool *out_value) FL_NO_EXCEPT
FL_NO_INLINE TypeConversionResult json_convert_to_string_core(const json_value &val, fl::string *out_value) FL_NO_EXCEPT
Compile-time linker keep-alive hook for a single fl::Bus.
Definition bus_info.h:57
InputGamut g FL_NO_EXCEPT
Definition rgbw.h:121
Base definition for an LED controller.
Definition crgb.hpp:179