MessagePack for C++
char_ptr.hpp
Go to the documentation of this file.
1 //
2 // MessagePack for C++ static resolution routine
3 //
4 // Copyright (C) 2014-2015 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_CHAR_PTR_HPP
11 #define MSGPACK_V1_TYPE_CHAR_PTR_HPP
12 
13 #include "msgpack/versioning.hpp"
14 #include "msgpack/object_fwd.hpp"
17 
18 #include <cstring>
19 
20 namespace msgpack {
21 
25 
26 namespace adaptor {
27 
28 template <>
29 struct pack<const char*> {
30  template <typename Stream>
32  uint32_t size = checked_get_container_size(std::strlen(v));
33  o.pack_str(size);
34  o.pack_str_body(v, size);
35  return o;
36  }
37 };
38 
39 template <>
40 struct object_with_zone<const char*> {
41  void operator()(msgpack::object::with_zone& o, const char* v) const {
42  uint32_t size = checked_get_container_size(std::strlen(v));
44  char* ptr = static_cast<char*>(o.zone.allocate_align(size, MSGPACK_ZONE_ALIGNOF(char)));
45  o.via.str.ptr = ptr;
46  o.via.str.size = size;
47  std::memcpy(ptr, v, size);
48  }
49 };
50 
51 template <>
52 struct object<const char*> {
53  void operator()(msgpack::object& o, const char* v) const {
54  uint32_t size = checked_get_container_size(std::strlen(v));
56  o.via.str.ptr = v;
57  o.via.str.size = size;
58  }
59 };
60 
61 
62 template <>
63 struct pack<char*> {
64  template <typename Stream>
66  return o << static_cast<const char*>(v);
67  }
68 };
69 
70 template <>
71 struct object_with_zone<char*> {
72  void operator()(msgpack::object::with_zone& o, char* v) const {
73  o << static_cast<const char*>(v);
74  }
75 };
76 
77 template <>
78 struct object<char*> {
79  void operator()(msgpack::object& o, char* v) const {
80  o << static_cast<const char*>(v);
81  }
82 };
83 
84 } // namespace adaptor
85 
87 } // MSGPACK_API_VERSION_NAMESPACE(v1)
89 
90 } // namespace msgpack
91 
92 #endif // MSGPACK_V1_TYPE_CHAR_PTR_HPP
msgpack::type::STR
@ STR
Definition: object_fwd_decl.hpp:39
msgpack::packer
The class template that supports continuous packing.
Definition: adaptor_base_decl.hpp:24
msgpack::zone::allocate_align
void * allocate_align(size_t size, size_t align=MSGPACK_ZONE_ALIGN)
Definition: cpp03_zone.hpp:246
msgpack::adaptor::object_with_zone
Definition: adaptor_base.hpp:43
msgpack
Definition: adaptor_base.hpp:15
MSGPACK_ZONE_ALIGNOF
#define MSGPACK_ZONE_ALIGNOF(type)
Definition: cpp03_zone_decl.hpp:30
msgpack::object_str::ptr
const char * ptr
Definition: object_fwd.hpp:34
msgpack::packer::pack_str_body
packer< Stream > & pack_str_body(const char *b, uint32_t l)
Packing str body.
Definition: pack.hpp:1220
msgpack::checked_get_container_size
uint32_t checked_get_container_size(T size)
Definition: check_container_size.hpp:55
msgpack::adaptor::object< const char * >::operator()
void operator()(msgpack::object &o, const char *v) const
Definition: char_ptr.hpp:53
MSGPACK_API_VERSION_NAMESPACE
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:58
msgpack::object::via
union_type via
Definition: object_fwd.hpp:93
adaptor_base.hpp
msgpack::adaptor::object
Definition: adaptor_base.hpp:38
versioning.hpp
msgpack::type::size
std::size_t size(T const &t)
Definition: size_equal_only.hpp:24
object_fwd.hpp
msgpack::object_str::size
uint32_t size
Definition: object_fwd.hpp:33
msgpack::adaptor::object_with_zone< char * >::operator()
void operator()(msgpack::object::with_zone &o, char *v) const
Definition: char_ptr.hpp:72
msgpack::adaptor::object_with_zone< const char * >::operator()
void operator()(msgpack::object::with_zone &o, const char *v) const
Definition: char_ptr.hpp:41
msgpack::adaptor::object< char * >::operator()
void operator()(msgpack::object &o, char *v) const
Definition: char_ptr.hpp:79
check_container_size.hpp
msgpack::adaptor::pack
Definition: adaptor_base.hpp:32
msgpack::object
Object class that corresponding to MessagePack format object.
Definition: object_fwd.hpp:75
v2::object::with_zone::zone
msgpack::zone & zone
Definition: object.hpp:37
msgpack::packer::pack_str
packer< Stream > & pack_str(uint32_t l)
Packing str header and length.
Definition: pack.hpp:1197
v2::object::with_zone
Definition: object.hpp:35
msgpack::object::type
msgpack::type::object_type type
Definition: object_fwd.hpp:92
msgpack::object::union_type::str
msgpack::object_str str
Definition: object_fwd.hpp:87
msgpack::adaptor::pack< const char * >::operator()
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const char *v) const
Definition: char_ptr.hpp:31
msgpack::adaptor::pack< char * >::operator()
packer< Stream > & operator()(packer< Stream > &o, char *v) const
Definition: char_ptr.hpp:65