FastLED 3.10.9
Loading...
Searching...
No Matches

◆ to_string_native()

fl::string fl::json::to_string_native ( ) const

Definition at line 1406 of file json.cpp.hpp.

1406 {
1407 if (!mValue) {
1408 return "null";
1409 }
1410
1411 // Pass 1: measure the exact serialized length without allocating it.
1412 JsonCountSink counter;
1413 SerializerVisitor<JsonCountSink> measure{counter};
1414 measure.serialize_value(mValue.get());
1415
1416 // Pass 2: write into one exactly-sized buffer. If that buffer cannot be
1417 // allocated, return an empty string rather than a truncated document.
1418 fl::string result;
1419 result.reserve(counter.count);
1420 if (result.capacity() < counter.count) {
1421 return fl::string();
1422 }
1423 JsonStringSink sink{result};
1424 SerializerVisitor<JsonStringSink> write{sink};
1425 write.serialize_value(mValue.get());
1426 if (result.size() != counter.count) {
1427 return fl::string();
1428 }
1429 return result;
1430}
int counter
Definition Pintest.h:190
fl::shared_ptr< json_value > mValue
Definition json.h:263
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31

References counter, fl::FL_NO_EXCEPT, mValue, and fl::SerializerVisitor< Sink >::serialize_value().

Referenced by to_string(), fl::json_value::to_string(), and to_string_native_public().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: