DeepCover Embedded Security in IoT: Public-key Secured Data Paths
Dependencies: MaximInterface
PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags > Class Template Reference
Writer with indentation and spacing. More...
#include <prettywriter.h>
Inherits Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >.
Public Member Functions | |
PrettyWriter (OutputStream &os, StackAllocator *allocator=0, size_t levelDepth=Base::kDefaultLevelDepth) | |
Constructor. | |
PrettyWriter & | SetIndent (Ch indentChar, unsigned indentCharCount) |
Set custom indentation. | |
PrettyWriter & | SetFormatOptions (PrettyFormatOptions options) |
Set pretty writer formatting options. | |
bool | RawValue (const Ch *json, size_t length, Type type) |
Write a raw JSON value. | |
void | Reset (OutputStream &os) |
Reset the writer with a new stream. | |
bool | IsComplete () const |
Checks whether the output is a complete JSON. | |
void | SetMaxDecimalPlaces (int maxDecimalPlaces) |
Sets the maximum number of decimal places for double output. | |
bool | RawValue (const Ch *json, size_t length, Type type) |
Write a raw JSON value. | |
Implementation of Handler | |
| |
bool | Null () |
bool | Bool (bool b) |
bool | Int (int i) |
bool | Uint (unsigned u) |
bool | Int64 (int64_t i64) |
bool | Uint64 (uint64_t u64) |
bool | Double (double d) |
Writes the given double value to the stream. | |
bool | RawNumber (const Ch *str, SizeType length, bool copy=false) |
bool | String (const Ch *str, SizeType length, bool copy=false) |
bool | String (const std::basic_string< Ch > &str) |
bool | StartObject () |
bool | Key (const Ch *str, SizeType length, bool copy=false) |
bool | Key (const std::basic_string< Ch > &str) |
bool | EndObject (SizeType memberCount=0) |
bool | StartArray () |
bool | EndArray (SizeType memberCount=0) |
Convenience extensions | |
bool | String (const Ch *str) |
Simpler but slower overload. | |
bool | Key (const Ch *str) |
Implementation of Handler | |
| |
bool | RawNumber (const Ch *str, SizeType length, bool copy=false) |
bool | String (const Ch *str, SizeType length, bool copy=false) |
bool | String (const std::basic_string< Ch > &str) |
bool | Key (const Ch *str, SizeType length, bool copy=false) |
Convenience extensions | |
bool | String (const Ch *str) |
Simpler but slower overload. | |
bool | Key (const Ch *str) |
Detailed Description
template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
class PrettyWriter< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >
Writer with indentation and spacing.
- Template Parameters:
-
OutputStream Type of ouptut os. SourceEncoding Encoding of source string. TargetEncoding Encoding of output stream. StackAllocator Type of allocator for allocating memory of stack.
Definition at line 48 of file prettywriter.h.
Constructor & Destructor Documentation
PrettyWriter | ( | OutputStream & | os, |
StackAllocator * | allocator = 0 , |
||
size_t | levelDepth = Base::kDefaultLevelDepth |
||
) | [explicit] |
Constructor.
- Parameters:
-
os Output stream. allocator User supplied allocator. If it is null, it will create a private one. levelDepth Initial capacity of stack.
Definition at line 58 of file prettywriter.h.
Member Function Documentation
bool Double | ( | double | d ) |
Writes the given double
value to the stream.
- Parameters:
-
d The value to be written.
- Returns:
- Whether it is succeed.
Reimplemented from Writer< OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags >.
Definition at line 101 of file prettywriter.h.
bool IsComplete | ( | ) | const [inherited] |
bool RawValue | ( | const Ch * | json, |
size_t | length, | ||
Type | type | ||
) | [inherited] |
bool RawValue | ( | const Ch * | json, |
size_t | length, | ||
Type | type | ||
) |
Write a raw JSON value.
For user to write a stringified JSON as a value.
- Parameters:
-
json A well-formed JSON value. It should not contain null character within [0, length - 1] range. length Length of the json. type Type of the root of json.
- Note:
- When using PrettyWriter::RawValue(), the result json may not be indented correctly.
Definition at line 199 of file prettywriter.h.
void Reset | ( | OutputStream & | os ) | [inherited] |
Reset the writer with a new stream.
This function reset the writer with a new stream and default settings, in order to make a Writer object reusable for output multiple JSONs.
- Parameters:
-
os New output stream. Writer<OutputStream> writer(os1); writer.StartObject(); // ... writer.EndObject(); writer.Reset(os2); writer.StartObject(); // ... writer.EndObject();
PrettyWriter& SetFormatOptions | ( | PrettyFormatOptions | options ) |
Set pretty writer formatting options.
- Parameters:
-
options Formatting options.
Definition at line 85 of file prettywriter.h.
PrettyWriter& SetIndent | ( | Ch | indentChar, |
unsigned | indentCharCount | ||
) |
Set custom indentation.
- Parameters:
-
indentChar Character for indentation. Must be whitespace character (' ', '\t', '\n', '\r'). indentCharCount Number of indent characters for each indentation level.
- Note:
- The default indentation is 4 spaces.
Definition at line 75 of file prettywriter.h.
void SetMaxDecimalPlaces | ( | int | maxDecimalPlaces ) | [inherited] |
Sets the maximum number of decimal places for double output.
This setting truncates the output with specified number of decimal places.
For example,
writer.SetMaxDecimalPlaces(3); writer.StartArray(); writer.Double(0.12345); // "0.123" writer.Double(0.0001); // "0.0" writer.Double(1.234567890123456e30); // "1.234567890123456e30" (do not truncate significand for positive exponent) writer.Double(1.23e-4); // "0.0" (do truncate significand for negative exponent) writer.EndArray();
The default setting does not truncate any decimal places. You can restore to this setting by calling
writer.SetMaxDecimalPlaces(Writer::kDefaultMaxDecimalPlaces);
bool String | ( | const Ch * | str ) | [inherited] |
bool String | ( | const Ch * | str ) |
Simpler but slower overload.
Definition at line 185 of file prettywriter.h.
Generated on Tue Jul 12 2022 12:06:51 by 1.7.2