WPILibC++ 2023.4.3-108-ge5452e3
wpi::json::serializer Class Reference

#include </home/runner/work/allwpilib/allwpilib/wpiutil/src/main/native/thirdparty/json/include/wpi/json_serializer.h>

Public Member Functions

 serializer (raw_ostream &s, const char ichar, size_t indent_init_len=512)
 
 serializer (const serializer &)=delete
 
serializeroperator= (const serializer &)=delete
 
void dump (const json &val, const bool pretty_print, const bool ensure_ascii, const unsigned int indent_step, const unsigned int current_indent=0)
 internal implementation of the serialization function More...
 
void dump_escaped (std::string_view s, const bool ensure_ascii)
 dump escaped string More...
 
template<typename NumberType , detail::enable_if_t< std::is_same_v< NumberType, uint64_t >, int > = 0>
bool is_negative_integer (NumberType x)
 
template<typename NumberType , detail::enable_if_t< std::is_same_v< NumberType, int64_t >, int > = 0>
bool is_negative_integer (NumberType x)
 
template<typename NumberType , detail::enable_if_t< std::is_same< NumberType, uint64_t >::value or std::is_same< NumberType, int64_t >::value, int > = 0>
void dump_integer (NumberType x)
 dump an integer More...
 
void dump_float (double x)
 dump a floating-point number More...
 

Static Public Member Functions

static uint8_t decode (uint8_t &state, uint32_t &codep, const uint8_t byte) noexcept
 check whether a string is UTF-8 encoded More...
 

Constructor & Destructor Documentation

◆ serializer() [1/2]

wpi::json::serializer::serializer ( raw_ostream s,
const char  ichar,
size_t  indent_init_len = 512 
)
inline
Parameters
[in]soutput stream to serialize to
[in]icharindentation character to use
[in]indent_init_leninitial length of indentation string buffer

◆ serializer() [2/2]

wpi::json::serializer::serializer ( const serializer )
delete

Member Function Documentation

◆ decode()

static uint8_t wpi::json::serializer::decode ( uint8_t &  state,
uint32_t &  codep,
const uint8_t  byte 
)
staticnoexcept

check whether a string is UTF-8 encoded

The function checks each byte of a string whether it is UTF-8 encoded. The result of the check is stored in the state parameter. The function must be called initially with state 0 (accept). State 1 means the string must be rejected, because the current byte is not allowed. If the string is completely processed, but the state is non-zero, the string ended prematurely; that is, the last byte indicated more bytes should have followed.

Parameters
[in,out]statethe state of the decoding
[in,out]codepcodepoint (valid only if resulting state is UTF8_ACCEPT)
[in]bytenext byte to decode
Returns
new state
Note
The function has been edited: a std::array is used.
See also
http://bjoern.hoehrmann.de/utf-8/decoder/dfa/

◆ dump()

void wpi::json::serializer::dump ( const json val,
const bool  pretty_print,
const bool  ensure_ascii,
const unsigned int  indent_step,
const unsigned int  current_indent = 0 
)

internal implementation of the serialization function

This function is called by the public member function dump and organizes the serialization internally. The indentation level is propagated as additional parameter. In case of arrays and objects, the function is called recursively.

  • strings and object keys are escaped using escape_string()
  • integer numbers are converted implicitly via operator<<
  • floating-point numbers are converted to a string using "%g" format
Parameters
[in]valvalue to serialize
[in]pretty_printwhether the output shall be pretty-printed
[in]ensure_asciiwhether the output shall only use ASCII chars
[in]indent_stepthe indent level
[in]current_indentthe current indent level (only used internally)

◆ dump_escaped()

void wpi::json::serializer::dump_escaped ( std::string_view  s,
const bool  ensure_ascii 
)

dump escaped string

Escape a string by replacing certain special characters by a sequence of an escape character (backslash) and another character and other control characters by a sequence of "\u" followed by a four-digit hex representation. The escaped string is written to output stream o.

Parameters
[in]sthe string to escape
[in]ensure_asciiwhether to escape non-ASCII characters with "\uXXXX" sequences

Complexity: Linear in the length of string s.

◆ dump_float()

void wpi::json::serializer::dump_float ( double  x)

dump a floating-point number

Dump a given floating-point number to output stream o. Works internally with number_buffer.

Parameters
[in]xfloating-point number to dump

◆ dump_integer()

template<typename NumberType , detail::enable_if_t< std::is_same< NumberType, uint64_t >::value or std::is_same< NumberType, int64_t >::value, int > = 0>
void wpi::json::serializer::dump_integer ( NumberType  x)
inline

dump an integer

Dump a given integer to output stream o. Works internally with number_buffer.

Parameters
[in]xinteger number (signed or unsigned) to dump
Template Parameters
NumberTypeeither int64_t or uint64_t

◆ is_negative_integer() [1/2]

template<typename NumberType , detail::enable_if_t< std::is_same_v< NumberType, uint64_t >, int > = 0>
bool wpi::json::serializer::is_negative_integer ( NumberType  x)
inline

◆ is_negative_integer() [2/2]

template<typename NumberType , detail::enable_if_t< std::is_same_v< NumberType, int64_t >, int > = 0>
bool wpi::json::serializer::is_negative_integer ( NumberType  x)
inline

◆ operator=()

serializer & wpi::json::serializer::operator= ( const serializer )
delete

The documentation for this class was generated from the following file: