|
| 1 | +// |
| 2 | +// MessagePack for C++ static resolution routine |
| 3 | +// |
| 4 | +// Copyright (C) 2008-2015 FURUHASHI Sadayuki and KONDO Takatoshi |
| 5 | +// |
| 6 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +// you may not use this file except in compliance with the License. |
| 8 | +// You may obtain a copy of the License at |
| 9 | +// |
| 10 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +// |
| 12 | +// Unless required by applicable law or agreed to in writing, software |
| 13 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +// See the License for the specific language governing permissions and |
| 16 | +// limitations under the License. |
| 17 | +// |
| 18 | +#ifndef MSGPACK_TYPE_V4RAW_HPP |
| 19 | +#define MSGPACK_TYPE_V4RAW_HPP |
| 20 | + |
| 21 | +#include "msgpack/versioning.hpp" |
| 22 | +#include "msgpack/adaptor/adaptor_base.hpp" |
| 23 | +#include <cstring> |
| 24 | +#include <string> |
| 25 | + |
| 26 | +namespace msgpack { |
| 27 | + |
| 28 | +/// @cond |
| 29 | +MSGPACK_API_VERSION_NAMESPACE(v1) { |
| 30 | +/// @endcond |
| 31 | + |
| 32 | +namespace type { |
| 33 | + |
| 34 | +struct v4raw_ref { |
| 35 | + v4raw_ref() : size(0), ptr(nullptr) {} |
| 36 | + v4raw_ref(const char* p, uint32_t s) : size(s), ptr(p) {} |
| 37 | + |
| 38 | + uint32_t size; |
| 39 | + const char* ptr; |
| 40 | + |
| 41 | + std::string str() const { return std::string(ptr, size); } |
| 42 | + |
| 43 | + bool operator== (const v4raw_ref& x) const |
| 44 | + { |
| 45 | + return size == x.size && std::memcmp(ptr, x.ptr, size) == 0; |
| 46 | + } |
| 47 | + |
| 48 | + bool operator!= (const v4raw_ref& x) const |
| 49 | + { |
| 50 | + return !(*this == x); |
| 51 | + } |
| 52 | + |
| 53 | + bool operator< (const v4raw_ref& x) const |
| 54 | + { |
| 55 | + if(size == x.size) { return std::memcmp(ptr, x.ptr, size) < 0; } |
| 56 | + else { return size < x.size; } |
| 57 | + } |
| 58 | + |
| 59 | + bool operator> (const v4raw_ref& x) const |
| 60 | + { |
| 61 | + if(size == x.size) { return std::memcmp(ptr, x.ptr, size) > 0; } |
| 62 | + else { return size > x.size; } |
| 63 | + } |
| 64 | +}; |
| 65 | + |
| 66 | +} // namespace type |
| 67 | + |
| 68 | +namespace adaptor { |
| 69 | + |
| 70 | +template <> |
| 71 | +struct convert<msgpack::type::v4raw_ref> { |
| 72 | + msgpack::object const& operator()(msgpack::object const& o, msgpack::type::v4raw_ref& v) const { |
| 73 | + if(o.type != msgpack::type::STR) { throw msgpack::type_error(); } |
| 74 | + v.ptr = o.via.str.ptr; |
| 75 | + v.size = o.via.str.size; |
| 76 | + return o; |
| 77 | + } |
| 78 | +}; |
| 79 | + |
| 80 | +template <> |
| 81 | +struct pack<msgpack::type::v4raw_ref> { |
| 82 | + template <typename Stream> |
| 83 | + msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const msgpack::type::v4raw_ref& v) const { |
| 84 | + o.pack_v4raw(v.size); |
| 85 | + o.pack_v4raw_body(v.ptr, v.size); |
| 86 | + return o; |
| 87 | + } |
| 88 | +}; |
| 89 | + |
| 90 | +template <> |
| 91 | +struct object<msgpack::type::v4raw_ref> { |
| 92 | + void operator()(msgpack::object& o, const msgpack::type::v4raw_ref& v) const { |
| 93 | + o.type = msgpack::type::STR; |
| 94 | + o.via.str.ptr = v.ptr; |
| 95 | + o.via.str.size = v.size; |
| 96 | + } |
| 97 | +}; |
| 98 | + |
| 99 | +template <> |
| 100 | +struct object_with_zone<msgpack::type::v4raw_ref> { |
| 101 | + void operator()(msgpack::object::with_zone& o, const msgpack::type::v4raw_ref& v) const { |
| 102 | + static_cast<msgpack::object&>(o) << v; |
| 103 | + } |
| 104 | +}; |
| 105 | + |
| 106 | +} // namespace adaptor |
| 107 | + |
| 108 | +/// @cond |
| 109 | +} // MSGPACK_API_VERSION_NAMESPACE(v1) |
| 110 | +/// @endcond |
| 111 | + |
| 112 | +} // namespace msgpack |
| 113 | + |
| 114 | +#endif // MSGPACK_TYPE_V4RAW_HPP |
0 commit comments