CppWAMP
C++11 client library for the WAMP protocol
json.hpp
Go to the documentation of this file.
1 /*------------------------------------------------------------------------------
2  Copyright Butterfly Energy Systems 2014-2015, 2022.
3  Distributed under the Boost Software License, Version 1.0.
4  http://www.boost.org/LICENSE_1_0.txt
5 ------------------------------------------------------------------------------*/
6 
7 #ifndef CPPWAMP_JSON_HPP
8 #define CPPWAMP_JSON_HPP
9 
10 //------------------------------------------------------------------------------
13 //------------------------------------------------------------------------------
14 
15 #include <istream>
16 #include <memory>
17 #include <ostream>
18 #include <string>
19 #include "api.hpp"
20 #include "codec.hpp"
21 #include "config.hpp"
22 #include "variant.hpp"
23 
24 namespace wamp
25 {
26 
27 //------------------------------------------------------------------------------
37 //------------------------------------------------------------------------------
38 template <typename O, typename C = OutputCategoryTypeOf<O>>
39 class CPPWAMP_API BasicJsonEncoder
40 {
41 public:
42  using Output = O;
43  using OutputCategory = C;
44 
47 
50 
53  void encode(const Variant& variant, Output& output);
54 
55 private:
56  class Impl;
57  std::unique_ptr<Impl> impl_;
58 };
59 
62 
65 
68 
69 
70 //------------------------------------------------------------------------------
80 //------------------------------------------------------------------------------
81 template <typename I, typename C = InputCategoryTypeOf<I>>
82 class CPPWAMP_API BasicJsonDecoder
83 {
84 public:
85  using Input = I;
86  using InputCategory = C;
87 
90 
93 
95  CPPWAMP_NODISCARD std::error_code decode(const Input& input,
96  Variant& variant);
97 
98 private:
99  class Impl;
100  std::unique_ptr<Impl> impl_;
101 };
102 
103 //------------------------------------------------------------------------------
112 //------------------------------------------------------------------------------
113 template <typename I>
115 {
116 public:
117  using Input = I;
119 
122 
124  ~BasicJsonDecoder();
125 
127  CPPWAMP_NODISCARD std::error_code decode(Input& input, Variant& variant);
128 
129 private:
130  class Impl;
131  Impl* impl_;
132 };
133 
136 
139 
142 
143 
144 //------------------------------------------------------------------------------
147 //------------------------------------------------------------------------------
148 struct Json
149 {
150  template <typename TOutput,
151  typename TOutputCategory = OutputCategoryTypeOf<TOutput>>
153 
154  template <typename TInput,
155  typename TInputCategory = InputCategoryTypeOf<TInput>>
157 
159  static constexpr int id() {return KnownCodecIds::json();}
160 };
161 
162 } // namespace wamp
163 
164 #ifndef CPPWAMP_COMPILED_LIB
165  #include "internal/json.ipp"
166 #endif
167 
168 #endif // CPPWAMP_JSON_HPP
wamp::Json::id
static constexpr int id()
Obtains a numeric identifier associated with this codec.
Definition: json.hpp:159
wamp::Variant
Discriminated union container that represents a JSON value.
Definition: variant.hpp:134
wamp::Json
JSON format tag type.
Definition: json.hpp:148
api.hpp
Defines macros related to exporting/importing APIs.
wamp::BasicJsonDecoder
JSON decoder.
Definition: json.hpp:82
wamp::encode
void encode(const Variant &variant, TOutput &&output)
Encodes the given variant to the given byte container or stream.
Definition: codec.hpp:103
wamp::StreamInputCategory
Input category for input streams of bytes.
Definition: codec.hpp:119
wamp
Definition: anyhandler.hpp:36
wamp::OutputCategoryTypeOf
typename OutputCategory< ValueTypeOf< O > >::type OutputCategoryTypeOf
Yields the category type that best matches the given output type.
Definition: codec.hpp:79
wamp::BasicJsonEncoder
JSON encoder.
Definition: json.hpp:39
wamp::InputCategoryTypeOf
typename InputCategory< ValueTypeOf< I > >::type InputCategoryTypeOf
Yields the category type that best matches the given input type.
Definition: codec.hpp:148
variant.hpp
Contains the declaration of Variant and other closely related types/functions.
wamp::decode
std::error_code decode(TInput &&input, Variant &variant)
Decodes from the given byte sequence or stream to the given variant.
Definition: codec.hpp:172
codec.hpp
Contains essential definitions for wamp::Variant codecs.