CppWAMP
C++11 client library for the WAMP protocol
msgpack.hpp
Go to the documentation of this file.
1 /*------------------------------------------------------------------------------
2  Copyright Butterfly Energy Systems 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_MSGPACK_HPP
8 #define CPPWAMP_MSGPACK_HPP
9 
10 //------------------------------------------------------------------------------
13 //------------------------------------------------------------------------------
14 
15 #include <memory>
16 #include <istream>
17 #include <ostream>
18 #include <string>
19 #include "api.hpp"
20 #include "codec.hpp"
21 #include "variant.hpp"
22 
23 namespace wamp
24 {
25 
26 //------------------------------------------------------------------------------
36 //------------------------------------------------------------------------------
37 template <typename O, typename C = OutputCategoryTypeOf<O>>
38 class CPPWAMP_API BasicMsgpackEncoder
39 {
40 public:
41  using Output = O;
42  using OutputCategory = C;
43 
46 
49 
52  void encode(const Variant& variant, Output& output);
53 
54 private:
55  class Impl;
56  std::unique_ptr<Impl> impl_;
57 };
58 
59 //------------------------------------------------------------------------------
68 //------------------------------------------------------------------------------
69 template <typename O>
71 {
72 public:
73  using Output = O;
75 
78 
81 
84  void encode(const Variant& variant, Output& output);
85 
86 private:
87  class Impl;
88  std::unique_ptr<Impl> impl_;
89 };
90 
93 
96 
99 
100 
101 //------------------------------------------------------------------------------
111 //------------------------------------------------------------------------------
112 template <typename I, typename C = InputCategoryTypeOf<I>>
113 class CPPWAMP_API BasicMsgpackDecoder
114 {
115 public:
116  using Input = I;
117  using InputCategory = C;
118 
121 
124 
126  CPPWAMP_NODISCARD std::error_code decode(const Input& input,
127  Variant& variant);
128 
129 private:
130  class Impl;
131  std::unique_ptr<Impl> impl_;
132 };
133 
134 //------------------------------------------------------------------------------
143 //------------------------------------------------------------------------------
144 template <typename I>
146 {
147 public:
148  using Input = I;
150 
153 
156 
158  CPPWAMP_NODISCARD std::error_code decode(Input& input, Variant& variant);
159 
160 private:
161  class Impl;
162  std::unique_ptr<Impl> impl_;
163 };
164 
167 
170 
173 
174 //------------------------------------------------------------------------------
177 //------------------------------------------------------------------------------
178 struct Msgpack
179 {
180  template <typename TOutput,
181  typename TOutputCategory = OutputCategoryTypeOf<TOutput>>
183 
184  template <typename TInput,
185  typename TInputCategory = InputCategoryTypeOf<TInput>>
187 
189  static constexpr int id() {return KnownCodecIds::msgpack();}
190 };
191 
192 } // namespace wamp
193 
194 #ifndef CPPWAMP_COMPILED_LIB
195 #include "internal/msgpack.ipp"
196 #endif
197 
198 #endif // CPPWAMP_MSGPACK_HPP
wamp::StreamOutputCategory
Output category for output streams of bytes.
Definition: codec.hpp:50
wamp::Variant
Discriminated union container that represents a JSON value.
Definition: variant.hpp:134
wamp::Msgpack
Msgpack format tag type.
Definition: msgpack.hpp:178
api.hpp
Defines macros related to exporting/importing APIs.
wamp::Msgpack::id
static constexpr int id()
Obtains a numeric identifier associated with this codec.
Definition: msgpack.hpp:189
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::BasicMsgpackEncoder
Msgpack encoder.
Definition: msgpack.hpp:38
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::BasicMsgpackDecoder
Decoder specialization for Msgpack.
Definition: msgpack.hpp:113
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.