Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: hello_message_pack
raw.hpp
00001 // 00002 // MessagePack for C++ static resolution routine 00003 // 00004 // Copyright (C) 2008-2009 FURUHASHI Sadayuki 00005 // 00006 // Distributed under the Boost Software License, Version 1.0. 00007 // (See accompanying file LICENSE_1_0.txt or copy at 00008 // http://www.boost.org/LICENSE_1_0.txt) 00009 // 00010 #ifndef MSGPACK_TYPE_RAW_HPP 00011 #define MSGPACK_TYPE_RAW_HPP 00012 00013 #include "msgpack/versioning.hpp" 00014 #include "msgpack/adaptor/adaptor_base.hpp" 00015 #include <cstring> 00016 #include <string> 00017 00018 namespace msgpack { 00019 00020 /// @cond 00021 MSGPACK_API_VERSION_NAMESPACE(v1) { 00022 /// @endcond 00023 00024 namespace type { 00025 00026 struct raw_ref { 00027 raw_ref() : size(0), ptr(nullptr) {} 00028 raw_ref(const char* p, uint32_t s) : size(s), ptr(p) {} 00029 00030 uint32_t size; 00031 const char* ptr; 00032 00033 std::string str() const { return std::string(ptr, size); } 00034 00035 bool operator== (const raw_ref& x) const 00036 { 00037 return size == x.size && std::memcmp(ptr, x.ptr, size) == 0; 00038 } 00039 00040 bool operator!= (const raw_ref& x) const 00041 { 00042 return !(*this == x); 00043 } 00044 00045 bool operator< (const raw_ref& x) const 00046 { 00047 if(size == x.size) { return std::memcmp(ptr, x.ptr, size) < 0; } 00048 else { return size < x.size; } 00049 } 00050 00051 bool operator> (const raw_ref& x) const 00052 { 00053 if(size == x.size) { return std::memcmp(ptr, x.ptr, size) > 0; } 00054 else { return size > x.size; } 00055 } 00056 }; 00057 00058 } // namespace type 00059 00060 namespace adaptor { 00061 00062 template <> 00063 struct convert<msgpack::type::raw_ref> { 00064 msgpack::object const& operator()(msgpack::object const& o, msgpack::type::raw_ref& v) const { 00065 if(o.type != msgpack::type::BIN) { 00066 // throw msgpack::type_error(); 00067 } 00068 v.ptr = o.via.bin.ptr; 00069 v.size = o.via.bin.size; 00070 return o; 00071 } 00072 }; 00073 00074 template <> 00075 struct pack<msgpack::type::raw_ref> { 00076 template <typename Stream> 00077 msgpack::packer<Stream> & operator()(msgpack::packer<Stream> & o, const msgpack::type::raw_ref& v) const { 00078 o.pack_bin(v.size); 00079 o.pack_bin_body(v.ptr, v.size); 00080 return o; 00081 } 00082 }; 00083 00084 template <> 00085 struct object<msgpack::type::raw_ref> { 00086 void operator()(msgpack::object& o, const msgpack::type::raw_ref& v) const { 00087 o.type = msgpack::type::BIN; 00088 o.via.bin.ptr = v.ptr; 00089 o.via.bin.size = v.size; 00090 } 00091 }; 00092 00093 template <> 00094 struct object_with_zone<msgpack::type::raw_ref> { 00095 void operator()(msgpack::object::with_zone& o, const msgpack::type::raw_ref& v) const { 00096 static_cast<msgpack::object&>(o) << v; 00097 } 00098 }; 00099 00100 } // namespace adaptor 00101 00102 /// @cond 00103 } // MSGPACK_API_VERSION_NAMESPACE(v1) 00104 /// @endcond 00105 00106 } // namespace msgpack 00107 00108 #endif // MSGPACK_TYPE_RAW_HPP
Generated on Tue Jul 12 2022 22:51:46 by
1.7.2