Zserio C++17 runtime library  0.5.0
Built for Zserio 2.17.0
JsonEncoder.h
Go to the documentation of this file.
1 #ifndef ZSERIO_JSON_ENCODER_H_INC
2 #define ZSERIO_JSON_ENCODER_H_INC
3 
4 #include <string_view>
5 #include <type_traits>
6 
8 #include "zserio/String.h"
10 
11 namespace zserio
12 {
13 
18 {
19 public:
25  static void encodeNull(std::ostream& stream);
26 
33  static void encodeBool(std::ostream& stream, bool value);
34 
41  template <typename T>
42  static void encodeIntegral(std::ostream& stream, T value);
43 
50  static void encodeFloatingPoint(std::ostream& stream, double value);
51 
60  static void encodeString(std::ostream& stream, std::string_view value);
61 };
62 
63 template <typename T>
64 void JsonEncoder::encodeIntegral(std::ostream& stream, T value)
65 {
66  using U = typename std::conditional<std::is_signed<T>::value, int64_t, uint64_t>::type;
67  stream << static_cast<U>(value);
68 }
69 
70 } // namespace zserio
71 
72 #endif // ZSERIO_JSON_ENCODER_H_INC
static void encodeFloatingPoint(std::ostream &stream, double value)
Definition: JsonEncoder.cpp:20
static void encodeNull(std::ostream &stream)
Definition: JsonEncoder.cpp:10
static void encodeBool(std::ostream &stream, bool value)
Definition: JsonEncoder.cpp:15
static void encodeIntegral(std::ostream &stream, T value)
Definition: JsonEncoder.h:64
static void encodeString(std::ostream &stream, std::string_view value)
Definition: JsonEncoder.cpp:50