MessagePack for C++
fixint.hpp
Go to the documentation of this file.
1 //
2 // MessagePack for C++ static resolution routine
3 //
4 // Copyright (C) 2020 FURUHASHI Sadayuki
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 //
10 #ifndef MSGPACK_TYPE_FIXINT_HPP
11 #define MSGPACK_TYPE_FIXINT_HPP
12 
13 #include "msgpack/versioning.hpp"
15 #include "msgpack/adaptor/int.hpp"
16 
17 namespace msgpack {
18 
22 
23 namespace type {
24 
25 
26 template <typename T>
27 struct fix_int {
28  fix_int() : value(0) { }
29  fix_int(T value) : value(value) { }
30 
31  operator T() const { return value; }
32 
33  T get() const { return value; }
34 
35 private:
36  T value;
37 };
38 
39 
44 
49 
50 
51 } // namespace type
52 
53 namespace adaptor {
54 
55 template <>
56 struct convert<type::fix_int8> {
58  { v = type::detail::convert_integer<int8_t>(o); return o; }
59 };
60 
61 template <>
62 struct convert<type::fix_int16> {
64  { v = type::detail::convert_integer<int16_t>(o); return o; }
65 };
66 
67 template <>
68 struct convert<type::fix_int32> {
70  { v = type::detail::convert_integer<int32_t>(o); return o; }
71 };
72 
73 template <>
74 struct convert<type::fix_int64> {
76  { v = type::detail::convert_integer<int64_t>(o); return o; }
77 };
78 
79 
80 template <>
81 struct convert<type::fix_uint8> {
83  { v = type::detail::convert_integer<uint8_t>(o); return o; }
84 };
85 
86 template <>
87 struct convert<type::fix_uint16> {
89  { v = type::detail::convert_integer<uint16_t>(o); return o; }
90 };
91 
92 template <>
93 struct convert<type::fix_uint32> {
95  { v = type::detail::convert_integer<uint32_t>(o); return o; }
96 };
97 
98 template <>
99 struct convert<type::fix_uint64> {
101  { v = type::detail::convert_integer<uint64_t>(o); return o; }
102 };
103 
104 template <>
105 struct pack<type::fix_int8> {
106  template <typename Stream>
108  { o.pack_fix_int8(v); return o; }
109 };
110 
111 template <>
112 struct pack<type::fix_int16> {
113  template <typename Stream>
115  { o.pack_fix_int16(v); return o; }
116 };
117 
118 template <>
119 struct pack<type::fix_int32> {
120  template <typename Stream>
122  { o.pack_fix_int32(v); return o; }
123 };
124 
125 template <>
126 struct pack<type::fix_int64> {
127  template <typename Stream>
129  { o.pack_fix_int64(v); return o; }
130 };
131 
132 
133 template <>
134 struct pack<type::fix_uint8> {
135  template <typename Stream>
137  { o.pack_fix_uint8(v); return o; }
138 };
139 
140 template <>
141 struct pack<type::fix_uint16> {
142  template <typename Stream>
144  { o.pack_fix_uint16(v); return o; }
145 };
146 
147 template <>
148 struct pack<type::fix_uint32> {
149  template <typename Stream>
151  { o.pack_fix_uint32(v); return o; }
152 };
153 
154 template <>
155 struct pack<type::fix_uint64> {
156  template <typename Stream>
158  { o.pack_fix_uint64(v); return o; }
159 };
160 
161 template <>
162 struct object<type::fix_int8> {
164  if (v.get() < 0) {
166  o.via.i64 = v.get();
167  }
168  else {
170  o.via.u64 = v.get();
171  }
172  }
173 };
174 
175 template <>
176 struct object<type::fix_int16> {
178  if(v.get() < 0) {
180  o.via.i64 = v.get();
181  }
182  else {
184  o.via.u64 = v.get();
185  }
186  }
187 };
188 
189 template <>
190 struct object<type::fix_int32> {
192  if (v.get() < 0) {
194  o.via.i64 = v.get();
195  }
196  else {
198  o.via.u64 = v.get();
199  }
200  }
201 };
202 
203 template <>
204 struct object<type::fix_int64> {
206  if (v.get() < 0) {
208  o.via.i64 = v.get();
209  }
210  else {
212  o.via.u64 = v.get();
213  }
214  }
215 };
216 
217 template <>
218 struct object<type::fix_uint8> {
221 };
222 
223 template <>
224 struct object<type::fix_uint16> {
227 };
228 
229 template <>
230 struct object<type::fix_uint32> {
233 };
234 
235 template <>
236 struct object<type::fix_uint64> {
239 };
240 
241 template <>
242 struct object_with_zone<type::fix_int8> {
244  { static_cast<msgpack::object&>(o) << v; }
245 };
246 
247 template <>
250  { static_cast<msgpack::object&>(o) << v; }
251 };
252 
253 template <>
256  { static_cast<msgpack::object&>(o) << v; }
257 };
258 
259 template <>
262  { static_cast<msgpack::object&>(o) << v; }
263 };
264 
265 
266 template <>
269  { static_cast<msgpack::object&>(o) << v; }
270 };
271 
272 template <>
275  { static_cast<msgpack::object&>(o) << v; }
276 };
277 
278 template <>
281  { static_cast<msgpack::object&>(o) << v; }
282 };
283 
284 template <>
287  { static_cast<msgpack::object&>(o) << v; }
288 };
289 
290 } // namespace adaptor
291 
293 } // MSGPACK_API_VERSION_NAMESPACE(v1)
295 
296 } // namespace msgpack
297 
298 #endif /* msgpack/type/fixint.hpp */
packer< Stream > & pack_fix_uint16(uint16_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:749
fix_int< uint32_t > fix_uint32
Definition: fixint.hpp:42
packer< Stream > & pack_fix_uint32(uint32_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:758
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:58
void operator()(msgpack::object::with_zone &o, type::fix_int64 v) const
Definition: fixint.hpp:261
void operator()(msgpack::object::with_zone &o, type::fix_int8 v) const
Definition: fixint.hpp:243
msgpack::object const & operator()(msgpack::object const &o, type::fix_int16 &v) const
Definition: fixint.hpp:63
void operator()(msgpack::object::with_zone &o, type::fix_uint8 v) const
Definition: fixint.hpp:268
fix_int< uint64_t > fix_uint64
Definition: fixint.hpp:43
void operator()(msgpack::object::with_zone &o, type::fix_int16 v) const
Definition: fixint.hpp:249
union_type via
Definition: object_fwd.hpp:123
void operator()(msgpack::object &o, type::fix_int8 v) const
Definition: fixint.hpp:163
void operator()(msgpack::object &o, type::fix_uint64 v) const
Definition: fixint.hpp:237
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_int64 &v) const
Definition: fixint.hpp:128
void operator()(msgpack::object &o, type::fix_int16 v) const
Definition: fixint.hpp:177
fix_int(T value)
Definition: fixint.hpp:29
fix_int< uint8_t > fix_uint8
Definition: fixint.hpp:40
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_int32 &v) const
Definition: fixint.hpp:121
msgpack::object const & operator()(msgpack::object const &o, type::fix_int64 &v) const
Definition: fixint.hpp:75
Definition: adaptor_base.hpp:15
void operator()(msgpack::object &o, type::fix_int32 v) const
Definition: fixint.hpp:191
msgpack::object const & operator()(msgpack::object const &o, type::fix_int8 &v) const
Definition: fixint.hpp:57
Definition: object_fwd.hpp:260
msgpack::object const & operator()(msgpack::object const &o, type::fix_int32 &v) const
Definition: fixint.hpp:69
fix_int< int64_t > fix_int64
Definition: fixint.hpp:48
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_int8 &v) const
Definition: fixint.hpp:107
int64_t i64
Definition: object_fwd.hpp:110
Definition: object_fwd.hpp:32
void operator()(msgpack::object::with_zone &o, type::fix_uint64 v) const
Definition: fixint.hpp:286
Definition: adaptor_base.hpp:45
void operator()(msgpack::object::with_zone &o, type::fix_uint32 v) const
Definition: fixint.hpp:280
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_int16 &v) const
Definition: fixint.hpp:114
void operator()(msgpack::object &o, type::fix_uint8 v) const
Definition: fixint.hpp:219
void operator()(msgpack::object &o, type::fix_int64 v) const
Definition: fixint.hpp:205
Definition: adaptor_base.hpp:34
fix_int< int8_t > fix_int8
Definition: fixint.hpp:45
packer< Stream > & pack_fix_int32(int32_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:793
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_uint16 &v) const
Definition: fixint.hpp:143
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_uint64 &v) const
Definition: fixint.hpp:157
void operator()(msgpack::object &o, type::fix_uint16 v) const
Definition: fixint.hpp:225
T get() const
Definition: fixint.hpp:33
msgpack::object const & operator()(msgpack::object const &o, type::fix_uint8 &v) const
Definition: fixint.hpp:82
Object class that corresponding to MessagePack format object.
Definition: object_fwd.hpp:106
Definition: fixint.hpp:27
msgpack::type::object_type type
Definition: object_fwd.hpp:122
packer< Stream > & pack_fix_int16(int16_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:784
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_uint8 &v) const
Definition: fixint.hpp:136
msgpack::object const & operator()(msgpack::object const &o, type::fix_uint64 &v) const
Definition: fixint.hpp:100
packer< Stream > & pack_fix_int8(int8_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:776
void operator()(msgpack::object &o, type::fix_uint32 v) const
Definition: fixint.hpp:231
msgpack::object const & operator()(msgpack::object const &o, type::fix_uint32 &v) const
Definition: fixint.hpp:94
void operator()(msgpack::object::with_zone &o, type::fix_int32 v) const
Definition: fixint.hpp:255
Definition: adaptor_base.hpp:40
The class template that supports continuous packing.
Definition: adaptor_base.hpp:22
fix_int< uint16_t > fix_uint16
Definition: fixint.hpp:41
void operator()(msgpack::object::with_zone &o, type::fix_uint16 v) const
Definition: fixint.hpp:274
packer< Stream > & pack_fix_uint8(uint8_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:741
fix_int< int32_t > fix_int32
Definition: fixint.hpp:47
fix_int< int16_t > fix_int16
Definition: fixint.hpp:46
fix_int()
Definition: fixint.hpp:28
packer< Stream > & pack_fix_uint64(uint64_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:767
msgpack::object const & operator()(msgpack::object const &o, type::fix_uint16 &v) const
Definition: fixint.hpp:88
Definition: adaptor_base.hpp:29
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::fix_uint32 &v) const
Definition: fixint.hpp:150
Definition: object_fwd.hpp:31
uint64_t u64
Definition: object_fwd.hpp:109
packer< Stream > & pack_fix_int64(int64_t d)
Packing uint8 (fixed packed type).
Definition: pack.hpp:802