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
char_ptr.hpp
00001 // 00002 // MessagePack for C++ static resolution routine 00003 // 00004 // Copyright (C) 2014-2015 KONDO Takatoshi 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_CHAR_PTR_HPP 00011 #define MSGPACK_TYPE_CHAR_PTR_HPP 00012 00013 #include "msgpack/versioning.hpp" 00014 #include "msgpack/object_fwd.hpp" 00015 #include "msgpack/adaptor/check_container_size.hpp" 00016 00017 #include <cstring> 00018 00019 namespace msgpack { 00020 00021 /// @cond 00022 MSGPACK_API_VERSION_NAMESPACE(v1) { 00023 /// @endcond 00024 00025 namespace adaptor { 00026 00027 template <> 00028 struct pack<const char*> { 00029 template <typename Stream> 00030 msgpack::packer<Stream> & operator()(msgpack::packer<Stream> & o, const char* v) const { 00031 uint32_t size = checked_get_container_size(std::strlen(v)); 00032 o.pack_str(size); 00033 o.pack_str_body(v, size); 00034 return o; 00035 } 00036 }; 00037 00038 template <> 00039 struct object_with_zone<const char*> { 00040 void operator()(msgpack::object::with_zone& o, const char* v) const { 00041 uint32_t size = checked_get_container_size(std::strlen(v)); 00042 o.type = msgpack::type::STR; 00043 char* ptr = static_cast<char*>(o.zone.allocate_align(size)); 00044 o.via.str.ptr = ptr; 00045 o.via.str.size = size; 00046 std::memcpy(ptr, v, size); 00047 } 00048 }; 00049 00050 template <> 00051 struct object<const char*> { 00052 void operator()(msgpack::object& o, const char* v) const { 00053 uint32_t size = checked_get_container_size(std::strlen(v)); 00054 o.type = msgpack::type::STR; 00055 o.via.str.ptr = v; 00056 o.via.str.size = size; 00057 } 00058 }; 00059 00060 00061 template <> 00062 struct pack<char*> { 00063 template <typename Stream> 00064 packer<Stream>& operator()(packer<Stream>& o, char* v) const { 00065 return o << static_cast<const char*>(v); 00066 } 00067 }; 00068 00069 template <> 00070 struct object_with_zone<char*> { 00071 void operator()(msgpack::object::with_zone& o, char* v) const { 00072 o << static_cast<const char*>(v); 00073 } 00074 }; 00075 00076 template <> 00077 struct object<char*> { 00078 void operator()(msgpack::object& o, char* v) const { 00079 o << static_cast<const char*>(v); 00080 } 00081 }; 00082 00083 template <std::size_t N> 00084 struct pack<char[N]> { 00085 template <typename Stream> 00086 msgpack::packer<Stream> & operator()(msgpack::packer<Stream> & o, const char* v) const { 00087 uint32_t size = checked_get_container_size(std::strlen(v)); 00088 o.pack_str(size); 00089 o.pack_str_body(v, size); 00090 return o; 00091 } 00092 }; 00093 00094 template <std::size_t N> 00095 struct object_with_zone<char[N]> { 00096 void operator()(msgpack::object::with_zone& o, const char* v) const { 00097 uint32_t size = checked_get_container_size(std::strlen(v)); 00098 o.type = msgpack::type::STR; 00099 char* ptr = static_cast<char*>(o.zone.allocate_align(size)); 00100 o.via.str.ptr = ptr; 00101 o.via.str.size = size; 00102 std::memcpy(ptr, v, size); 00103 } 00104 }; 00105 00106 template <std::size_t N> 00107 struct object<char[N]> { 00108 void operator()(msgpack::object& o, const char* v) const { 00109 uint32_t size = checked_get_container_size(std::strlen(v)); 00110 o.type = msgpack::type::STR; 00111 o.via.str.ptr = v; 00112 o.via.str.size = size; 00113 } 00114 }; 00115 00116 template <std::size_t N> 00117 struct pack<const char[N]> { 00118 template <typename Stream> 00119 msgpack::packer<Stream> & operator()(msgpack::packer<Stream> & o, const char* v) const { 00120 uint32_t size = checked_get_container_size(std::strlen(v)); 00121 o.pack_str(size); 00122 o.pack_str_body(v, size); 00123 return o; 00124 } 00125 }; 00126 00127 template <std::size_t N> 00128 struct object_with_zone<const char[N]> { 00129 void operator()(msgpack::object::with_zone& o, const char* v) const { 00130 uint32_t size = checked_get_container_size(std::strlen(v)); 00131 o.type = msgpack::type::STR; 00132 char* ptr = static_cast<char*>(o.zone.allocate_align(size)); 00133 o.via.str.ptr = ptr; 00134 o.via.str.size = size; 00135 std::memcpy(ptr, v, size); 00136 } 00137 }; 00138 00139 template <std::size_t N> 00140 struct object<const char[N]> { 00141 void operator()(msgpack::object& o, const char* v) const { 00142 uint32_t size = checked_get_container_size(std::strlen(v)); 00143 o.type = msgpack::type::STR; 00144 o.via.str.ptr = v; 00145 o.via.str.size = size; 00146 } 00147 }; 00148 00149 } // namespace adaptor 00150 00151 /// @cond 00152 } // MSGPACK_API_VERSION_NAMESPACE(v1) 00153 /// @endcond 00154 00155 } // namespace msgpack 00156 00157 #endif // MSGPACK_TYPE_CHAR_PTR_HPP
Generated on Tue Jul 12 2022 22:51:44 by
1.7.2