MessagePack for C++
Loading...
Searching...
No Matches
fixint.hpp
Go to the documentation of this file.
1//
2// MessagePack for C++ static resolution routine
3//
4// Copyright (C) 2016 FURUHASHI Sadayuki and KONDO Takatoshi
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_V1_TYPE_FIXINT_HPP
11#define MSGPACK_V1_TYPE_FIXINT_HPP
12
14
15namespace msgpack {
16
20
21namespace type {
22
23template <typename T>
24struct fix_int {
25 typedef T value_type;
26 fix_int() : value(0) { }
27 fix_int(T value) : value(value) { }
28
29 operator T() const { return value; }
30
31 T get() const { return value; }
32
33private:
34 T value;
35};
36
37} // namespace type
38
39namespace adaptor {
40
41template <>
42struct convert<type::fix_int8> {
44 { v = type::detail::convert_integer<int8_t>(o); return o; }
45};
46
47template <>
48struct convert<type::fix_int16> {
50 { v = type::detail::convert_integer<int16_t>(o); return o; }
51};
52
53template <>
54struct convert<type::fix_int32> {
56 { v = type::detail::convert_integer<int32_t>(o); return o; }
57};
58
59template <>
60struct convert<type::fix_int64> {
62 { v = type::detail::convert_integer<int64_t>(o); return o; }
63};
64
65
66template <>
67struct convert<type::fix_uint8> {
69 { v = type::detail::convert_integer<uint8_t>(o); return o; }
70};
71
72template <>
73struct convert<type::fix_uint16> {
75 { v = type::detail::convert_integer<uint16_t>(o); return o; }
76};
77
78template <>
79struct convert<type::fix_uint32> {
81 { v = type::detail::convert_integer<uint32_t>(o); return o; }
82};
83
84template <>
85struct convert<type::fix_uint64> {
87 { v = type::detail::convert_integer<uint64_t>(o); return o; }
88};
89
90template <>
91struct pack<type::fix_int8> {
92 template <typename Stream>
94 { o.pack_fix_int8(v); return o; }
95};
96
97template <>
98struct pack<type::fix_int16> {
99 template <typename Stream>
101 { o.pack_fix_int16(v); return o; }
102};
103
104template <>
105struct pack<type::fix_int32> {
106 template <typename Stream>
108 { o.pack_fix_int32(v); return o; }
109};
110
111template <>
112struct pack<type::fix_int64> {
113 template <typename Stream>
115 { o.pack_fix_int64(v); return o; }
116};
117
118
119template <>
120struct pack<type::fix_uint8> {
121 template <typename Stream>
123 { o.pack_fix_uint8(v); return o; }
124};
125
126template <>
127struct pack<type::fix_uint16> {
128 template <typename Stream>
130 { o.pack_fix_uint16(v); return o; }
131};
132
133template <>
134struct pack<type::fix_uint32> {
135 template <typename Stream>
137 { o.pack_fix_uint32(v); return o; }
138};
139
140template <>
141struct pack<type::fix_uint64> {
142 template <typename Stream>
144 { o.pack_fix_uint64(v); return o; }
145};
146
147template <>
148struct object<type::fix_int8> {
149 void operator()(msgpack::object& o, type::fix_int8 v) const {
150 if (v.get() < 0) {
152 o.via.i64 = v.get();
153 }
154 else {
156 o.via.u64 = static_cast<uint64_t>(v.get());
157 }
158 }
159};
160
161template <>
162struct object<type::fix_int16> {
163 void operator()(msgpack::object& o, type::fix_int16 v) const {
164 if(v.get() < 0) {
166 o.via.i64 = v.get();
167 }
168 else {
170 o.via.u64 = static_cast<uint64_t>(v.get());
171 }
172 }
173};
174
175template <>
176struct object<type::fix_int32> {
177 void operator()(msgpack::object& o, type::fix_int32 v) const {
178 if (v.get() < 0) {
180 o.via.i64 = v.get();
181 }
182 else {
184 o.via.u64 = static_cast<uint64_t>(v.get());
185 }
186 }
187};
188
189template <>
190struct object<type::fix_int64> {
191 void operator()(msgpack::object& o, type::fix_int64 v) const {
192 if (v.get() < 0) {
194 o.via.i64 = v.get();
195 }
196 else {
198 o.via.u64 = static_cast<uint64_t>(v.get());
199 }
200 }
201};
202
203template <>
204struct object<type::fix_uint8> {
205 void operator()(msgpack::object& o, type::fix_uint8 v) const {
207 o.via.u64 = v.get();
208 }
209};
210
211template <>
212struct object<type::fix_uint16> {
215 o.via.u64 = v.get();
216 }
217};
218
219template <>
220struct object<type::fix_uint32> {
223 o.via.u64 = v.get();
224 }
225};
226
227template <>
228struct object<type::fix_uint64> {
231 o.via.u64 = v.get();
232 }
233};
234
235template <>
236struct object_with_zone<type::fix_int8> {
238 static_cast<msgpack::object&>(o) << v;
239 }
240};
241
242template <>
243struct object_with_zone<type::fix_int16> {
245 static_cast<msgpack::object&>(o) << v;
246 }
247};
248
249template <>
250struct object_with_zone<type::fix_int32> {
252 static_cast<msgpack::object&>(o) << v;
253 }
254};
255
256template <>
257struct object_with_zone<type::fix_int64> {
259 static_cast<msgpack::object&>(o) << v;
260 }
261};
262
263
264template <>
265struct object_with_zone<type::fix_uint8> {
267 static_cast<msgpack::object&>(o) << v;
268 }
269};
270
271template <>
272struct object_with_zone<type::fix_uint16> {
274 static_cast<msgpack::object&>(o) << v;
275 }
276};
277
278template <>
279struct object_with_zone<type::fix_uint32> {
281 static_cast<msgpack::object&>(o) << v;
282 }
283};
284
285template <>
286struct object_with_zone<type::fix_uint64> {
288 static_cast<msgpack::object&>(o) << v;
289 }
290};
291
292} // namespace adaptor
293
295} // MSGPACK_API_VERSION_NAMESPACE(v1)
297
298} // namespace msgpack
299
300#endif // MSGPACK_V1_TYPE_FIXINT_HPP
The class template that supports continuous packing.
Definition pack.hpp:33
packer< Stream > & pack_fix_int64(int64_t d)
Packing uint8 (fixed packed type).
Definition pack.hpp:822
packer< Stream > & pack_fix_uint64(uint64_t d)
Packing uint8 (fixed packed type).
Definition pack.hpp:787
packer< Stream > & pack_fix_int8(int8_t d)
Packing uint8 (fixed packed type).
Definition pack.hpp:796
packer< Stream > & pack_fix_int32(int32_t d)
Packing uint8 (fixed packed type).
Definition pack.hpp:813
packer< Stream > & pack_fix_uint16(uint16_t d)
Packing uint8 (fixed packed type).
Definition pack.hpp:769
packer< Stream > & pack_fix_uint32(uint32_t d)
Packing uint8 (fixed packed type).
Definition pack.hpp:778
packer< Stream > & pack_fix_int16(int16_t d)
Packing uint8 (fixed packed type).
Definition pack.hpp:804
packer< Stream > & pack_fix_uint8(uint8_t d)
Packing uint8 (fixed packed type).
Definition pack.hpp:761
fix_int< int8_t > fix_int8
Definition fixint_decl.hpp:34
fix_int< uint64_t > fix_uint64
Definition fixint_decl.hpp:32
fix_int< uint8_t > fix_uint8
Definition fixint_decl.hpp:29
fix_int< int32_t > fix_int32
Definition fixint_decl.hpp:36
fix_int< int16_t > fix_int16
Definition fixint_decl.hpp:35
fix_int< int64_t > fix_int64
Definition fixint_decl.hpp:37
fix_int< uint32_t > fix_uint32
Definition fixint_decl.hpp:31
@ POSITIVE_INTEGER
Definition object_fwd_decl.hpp:30
@ NEGATIVE_INTEGER
Definition object_fwd_decl.hpp:31
fix_int< uint16_t > fix_uint16
Definition fixint_decl.hpp:30
Definition adaptor_base.hpp:15
void pack(msgpack::packer< Stream > &o, const T &v)
Definition object.hpp:1185
void convert(T &v, msgpack::object const &o)
Definition object.hpp:1178
msgpack::object const & operator()(msgpack::object const &o, T &v) const
Definition object.hpp:646
void operator()(msgpack::object::with_zone &o, T const &v) const
Definition object.hpp:662
void operator()(msgpack::object &o, T const &v) const
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, T const &v) const
Definition object.hpp:655
Definition object.hpp:35
Object class that corresponding to MessagePack format object.
Definition object_fwd.hpp:75
union_type via
Definition object_fwd.hpp:93
msgpack::type::object_type type
Definition object_fwd.hpp:92
Definition fixint.hpp:24
fix_int(T value)
Definition fixint.hpp:27
T get() const
Definition fixint.hpp:31
fix_int()
Definition fixint.hpp:26
T value_type
Definition fixint.hpp:25
uint64_t u64
Definition object_fwd.hpp:78
int64_t i64
Definition object_fwd.hpp:79
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition versioning.hpp:66