FastLED 3.10.10
Loading...
Searching...
No Matches

◆ to_string_native()

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

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

1411 {
1412 if (!mValue) {
1413 return "null";
1414 }
1415
1416 // Pass 1: measure the exact serialized length without allocating it.
1417 JsonCountSink counter;
1418 SerializerVisitor<JsonCountSink> measure{counter};
1419 measure.serialize_value(mValue.get());
1420
1421 // Pass 2: write into one exactly-sized buffer. If that buffer cannot be
1422 // allocated, return an empty string rather than a truncated document.
1423 fl::string result;
1424 result.reserve(counter.count);
1425 if (result.capacity() < counter.count) {
1426 return fl::string();
1427 }
1428 JsonStringSink sink{result};
1429 SerializerVisitor<JsonStringSink> write{sink};
1430 write.serialize_value(mValue.get());
1431 if (result.size() != counter.count) {
1432 return fl::string();
1433 }
1434 return result;
1435}
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: