REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
|
The Streaming JSON API provides a way of constructing (writing) JSON messages without RAM overhead. More...
#include <streaming_json.h>
Public Member Functions | |
StreamingJson (Print &output) | |
void | check_comma () |
void | needs_comma () |
void | begin_dict () |
void | end_dict () |
void | begin_list () |
void | end_list () |
void | begin_str (char quote='"') |
void | end_str (char quote='"') |
void | key (const char *str, char quote='"') |
void | key (const std::string &str) |
void | val (const char *str, char quote='"') |
void | val (const std::string &str) |
void | val (bool b) |
template<typename V > | |
void | val (V i) |
void | null () |
void | json (const char *str) |
An embedded Raw json structure. | |
template<typename V > | |
void | kv (const char *_key, V _val) |
void | endln () |
Public Attributes | |
Print & | output |
Detailed Description
The Streaming JSON API provides a way of constructing (writing) JSON messages without RAM overhead.
In contrast to ArduinoJSON, there is no document which needs to be represented in memory and which is setup before serialization. Instead, serialization and printing happens here at method call time. Ideally, this uses the Arduino Print infrastructure and thus avoids any string representations where possible.
The class stores only a minimal state of parsing. JSON does not allow trailing commas so this is avoided with a simple state boolean. The lib is not aware of whether it constructs a map/dictionary or a list/array. It is up to the user to make sure the dict follows the key-value-key-value semantics.
Correct usage example:
StreamingJson s(some_client_or_so); s.begin_dict(); s.key("foo"); s.val("bar"); s.key("biz"); s.begin_list(); s.val(123); s.val(true); s.val(3.14); s.null(); s.end_list(); s.end_dict();
should create the following JSON document:
{"foo":"bar","biz":[123, true, 3.14, null]}
Definition at line 44 of file streaming_json.h.
Constructor & Destructor Documentation
◆ StreamingJson()
|
inline |
Definition at line 49 of file streaming_json.h.
Member Function Documentation
◆ begin_dict()
|
inline |
Definition at line 57 of file streaming_json.h.
References output.
Referenced by debug_print_json(), client::StreamingRunDataNotificationHandler::handle(), msg::StartupLog::stream_to_json(), and msg::StreamLogger::write().
◆ begin_list()
|
inline |
Definition at line 59 of file streaming_json.h.
References output.
Referenced by client::StreamingRunDataNotificationHandler::handle(), and msg::StartupLog::stream_to_json().
◆ begin_str()
|
inline |
Definition at line 62 of file streaming_json.h.
References output.
Referenced by key(), val(), and msg::StreamLogger::write().
◆ check_comma()
|
inline |
Definition at line 51 of file streaming_json.h.
References output.
Referenced by client::StreamingRunDataNotificationHandler::handle(), json(), key(), null(), val(), val(), and val().
◆ end_dict()
|
inline |
Definition at line 58 of file streaming_json.h.
References needs_comma(), and output.
Referenced by debug_print_json(), client::StreamingRunDataNotificationHandler::handle(), msg::StartupLog::stream_to_json(), and msg::StreamLogger::write().
◆ end_list()
|
inline |
Definition at line 60 of file streaming_json.h.
References needs_comma(), and output.
Referenced by client::StreamingRunDataNotificationHandler::handle(), and msg::StartupLog::stream_to_json().
◆ end_str()
|
inline |
Definition at line 63 of file streaming_json.h.
References output.
Referenced by key(), val(), and msg::StreamLogger::write().
◆ endln()
|
inline |
Definition at line 118 of file streaming_json.h.
References output.
Referenced by debug_print_json(), and client::StreamingRunDataNotificationHandler::handle().
◆ json()
|
inline |
An embedded Raw json structure.
Definition at line 108 of file streaming_json.h.
References check_comma(), needs_comma(), and output.
Referenced by client::StreamingRunDataNotificationHandler::handle(), and msg::StartupLog::stream_to_json().
◆ key() [1/2]
|
inline |
Definition at line 65 of file streaming_json.h.
References begin_str(), check_comma(), end_str(), and output.
Referenced by debug_print_json(), client::StreamingRunDataNotificationHandler::handle(), kv(), msg::StartupLog::stream_to_json(), and msg::StreamLogger::write().
◆ key() [2/2]
|
inline |
◆ kv()
|
inline |
Definition at line 116 of file streaming_json.h.
Referenced by debug_print_json(), client::StreamingRunDataNotificationHandler::handle(), msg::StartupLog::stream_to_json(), and msg::StreamLogger::write().
◆ needs_comma()
|
inline |
Definition at line 55 of file streaming_json.h.
Referenced by end_dict(), end_list(), client::StreamingRunDataNotificationHandler::handle(), json(), null(), val(), val(), and val().
◆ null()
|
inline |
Definition at line 101 of file streaming_json.h.
References check_comma(), needs_comma(), and output.
◆ val() [1/4]
|
inline |
Definition at line 87 of file streaming_json.h.
References check_comma(), needs_comma(), and output.
◆ val() [2/4]
|
inline |
Definition at line 77 of file streaming_json.h.
References begin_str(), check_comma(), end_str(), needs_comma(), and output.
Referenced by client::StreamingRunDataNotificationHandler::handle(), and kv().
◆ val() [3/4]
|
inline |
◆ val() [4/4]
|
inline |
Definition at line 95 of file streaming_json.h.
References check_comma(), needs_comma(), and output.
Member Data Documentation
◆ output
Print& utils::StreamingJson::output |
Definition at line 48 of file streaming_json.h.
Referenced by begin_dict(), begin_list(), begin_str(), check_comma(), end_dict(), end_list(), end_str(), endln(), json(), key(), null(), val(), val(), val(), and msg::StreamLogger::write().
The documentation for this class was generated from the following file:
- lib/controller/src/utils/streaming_json.h