123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- //
- // MessagePack for C++ static resolution routine
- //
- // Copyright (C) 2016 FURUHASHI Sadayuki and KONDO Takatoshi
- //
- // Distributed under the Boost Software License, Version 1.0.
- // (See accompanying file LICENSE_1_0.txt or copy at
- // http://www.boost.org/LICENSE_1_0.txt)
- //
- #ifndef MSGPACK_V1_TYPE_FIXINT_HPP
- #define MSGPACK_V1_TYPE_FIXINT_HPP
- #include "msgpack/v1/adaptor/fixint_decl.hpp"
- namespace msgpack {
- /// @cond
- MSGPACK_API_VERSION_NAMESPACE(v1) {
- /// @endcond
- namespace type {
- template <typename T>
- struct fix_int {
- fix_int() : value(0) { }
- fix_int(T value) : value(value) { }
- operator T() const { return value; }
- T get() const { return value; }
- private:
- T value;
- };
- } // namespace type
- namespace adaptor {
- template <>
- struct convert<type::fix_int8> {
- msgpack::object const& operator()(msgpack::object const& o, type::fix_int8& v) const
- { v = type::detail::convert_integer<int8_t>(o); return o; }
- };
- template <>
- struct convert<type::fix_int16> {
- msgpack::object const& operator()(msgpack::object const& o, type::fix_int16& v) const
- { v = type::detail::convert_integer<int16_t>(o); return o; }
- };
- template <>
- struct convert<type::fix_int32> {
- msgpack::object const& operator()(msgpack::object const& o, type::fix_int32& v) const
- { v = type::detail::convert_integer<int32_t>(o); return o; }
- };
- template <>
- struct convert<type::fix_int64> {
- msgpack::object const& operator()(msgpack::object const& o, type::fix_int64& v) const
- { v = type::detail::convert_integer<int64_t>(o); return o; }
- };
- template <>
- struct convert<type::fix_uint8> {
- msgpack::object const& operator()(msgpack::object const& o, type::fix_uint8& v) const
- { v = type::detail::convert_integer<uint8_t>(o); return o; }
- };
- template <>
- struct convert<type::fix_uint16> {
- msgpack::object const& operator()(msgpack::object const& o, type::fix_uint16& v) const
- { v = type::detail::convert_integer<uint16_t>(o); return o; }
- };
- template <>
- struct convert<type::fix_uint32> {
- msgpack::object const& operator()(msgpack::object const& o, type::fix_uint32& v) const
- { v = type::detail::convert_integer<uint32_t>(o); return o; }
- };
- template <>
- struct convert<type::fix_uint64> {
- msgpack::object const& operator()(msgpack::object const& o, type::fix_uint64& v) const
- { v = type::detail::convert_integer<uint64_t>(o); return o; }
- };
- template <>
- struct pack<type::fix_int8> {
- template <typename Stream>
- msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_int8& v) const
- { o.pack_fix_int8(v); return o; }
- };
- template <>
- struct pack<type::fix_int16> {
- template <typename Stream>
- msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_int16& v) const
- { o.pack_fix_int16(v); return o; }
- };
- template <>
- struct pack<type::fix_int32> {
- template <typename Stream>
- msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_int32& v) const
- { o.pack_fix_int32(v); return o; }
- };
- template <>
- struct pack<type::fix_int64> {
- template <typename Stream>
- msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_int64& v) const
- { o.pack_fix_int64(v); return o; }
- };
- template <>
- struct pack<type::fix_uint8> {
- template <typename Stream>
- msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_uint8& v) const
- { o.pack_fix_uint8(v); return o; }
- };
- template <>
- struct pack<type::fix_uint16> {
- template <typename Stream>
- msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_uint16& v) const
- { o.pack_fix_uint16(v); return o; }
- };
- template <>
- struct pack<type::fix_uint32> {
- template <typename Stream>
- msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_uint32& v) const
- { o.pack_fix_uint32(v); return o; }
- };
- template <>
- struct pack<type::fix_uint64> {
- template <typename Stream>
- msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_uint64& v) const
- { o.pack_fix_uint64(v); return o; }
- };
- template <>
- struct object<type::fix_int8> {
- void operator()(msgpack::object& o, type::fix_int8 v) const {
- if (v.get() < 0) {
- o.type = msgpack::type::NEGATIVE_INTEGER;
- o.via.i64 = v.get();
- }
- else {
- o.type = msgpack::type::POSITIVE_INTEGER;
- o.via.u64 = v.get();
- }
- }
- };
- template <>
- struct object<type::fix_int16> {
- void operator()(msgpack::object& o, type::fix_int16 v) const {
- if(v.get() < 0) {
- o.type = msgpack::type::NEGATIVE_INTEGER;
- o.via.i64 = v.get();
- }
- else {
- o.type = msgpack::type::POSITIVE_INTEGER;
- o.via.u64 = v.get();
- }
- }
- };
- template <>
- struct object<type::fix_int32> {
- void operator()(msgpack::object& o, type::fix_int32 v) const {
- if (v.get() < 0) {
- o.type = msgpack::type::NEGATIVE_INTEGER;
- o.via.i64 = v.get();
- }
- else {
- o.type = msgpack::type::POSITIVE_INTEGER;
- o.via.u64 = v.get();
- }
- }
- };
- template <>
- struct object<type::fix_int64> {
- void operator()(msgpack::object& o, type::fix_int64 v) const {
- if (v.get() < 0) {
- o.type = msgpack::type::NEGATIVE_INTEGER;
- o.via.i64 = v.get();
- }
- else {
- o.type = msgpack::type::POSITIVE_INTEGER;
- o.via.u64 = v.get();
- }
- }
- };
- template <>
- struct object<type::fix_uint8> {
- void operator()(msgpack::object& o, type::fix_uint8 v) const {
- o.type = msgpack::type::POSITIVE_INTEGER;
- o.via.u64 = v.get();
- }
- };
- template <>
- struct object<type::fix_uint16> {
- void operator()(msgpack::object& o, type::fix_uint16 v) const {
- o.type = msgpack::type::POSITIVE_INTEGER;
- o.via.u64 = v.get();
- }
- };
- template <>
- struct object<type::fix_uint32> {
- void operator()(msgpack::object& o, type::fix_uint32 v) const {
- o.type = msgpack::type::POSITIVE_INTEGER;
- o.via.u64 = v.get();
- }
- };
- template <>
- struct object<type::fix_uint64> {
- void operator()(msgpack::object& o, type::fix_uint64 v) const {
- o.type = msgpack::type::POSITIVE_INTEGER;
- o.via.u64 = v.get();
- }
- };
- template <>
- struct object_with_zone<type::fix_int8> {
- void operator()(msgpack::object::with_zone& o, type::fix_int8 v) const {
- static_cast<msgpack::object&>(o) << v;
- }
- };
- template <>
- struct object_with_zone<type::fix_int16> {
- void operator()(msgpack::object::with_zone& o, type::fix_int16 v) const {
- static_cast<msgpack::object&>(o) << v;
- }
- };
- template <>
- struct object_with_zone<type::fix_int32> {
- void operator()(msgpack::object::with_zone& o, type::fix_int32 v) const {
- static_cast<msgpack::object&>(o) << v;
- }
- };
- template <>
- struct object_with_zone<type::fix_int64> {
- void operator()(msgpack::object::with_zone& o, type::fix_int64 v) const {
- static_cast<msgpack::object&>(o) << v;
- }
- };
- template <>
- struct object_with_zone<type::fix_uint8> {
- void operator()(msgpack::object::with_zone& o, type::fix_uint8 v) const {
- static_cast<msgpack::object&>(o) << v;
- }
- };
- template <>
- struct object_with_zone<type::fix_uint16> {
- void operator()(msgpack::object::with_zone& o, type::fix_uint16 v) const {
- static_cast<msgpack::object&>(o) << v;
- }
- };
- template <>
- struct object_with_zone<type::fix_uint32> {
- void operator()(msgpack::object::with_zone& o, type::fix_uint32 v) const {
- static_cast<msgpack::object&>(o) << v;
- }
- };
- template <>
- struct object_with_zone<type::fix_uint64> {
- void operator()(msgpack::object::with_zone& o, type::fix_uint64 v) const {
- static_cast<msgpack::object&>(o) << v;
- }
- };
- } // namespace adaptor
- /// @cond
- } // MSGPACK_API_VERSION_NAMESPACE(v1)
- /// @endcond
- } // namespace msgpack
- #endif // MSGPACK_V1_TYPE_FIXINT_HPP
|