Zserio C++17 runtime library  1.1.0
Built for Zserio 2.18.1
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 <cstdint>
5 #include <string_view>
6 #include <type_traits>
7 
9 #include "zserio/String.h"
11 
12 namespace zserio
13 {
14 
19 {
20 public:
26  static void encodeNull(std::ostream& stream);
27 
34  static void encodeBool(std::ostream& stream, bool value);
35 
42  template <typename T>
43  static void encodeIntegral(std::ostream& stream, T value);
44 
51  static void encodeFloatingPoint(std::ostream& stream, double value);
52 
61  static void encodeString(std::ostream& stream, std::string_view value);
62 };
63 
64 template <typename T>
65 void JsonEncoder::encodeIntegral(std::ostream& stream, T value)
66 {
67  using U = typename std::conditional<std::is_signed<T>::value, int64_t, uint64_t>::type;
68  stream << static_cast<U>(value);
69 }
70 
71 } // namespace zserio
72 
73 #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:65
static void encodeString(std::ostream &stream, std::string_view value)
Definition: JsonEncoder.cpp:50