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
The class template that supports continuous packing.
Definition: pack.hpp:33
packer< Stream > & pack_str_body(const char *b, uint32_t l)
Packing str body.
Definition: pack.hpp:1255
packer< Stream > & pack_str(uint32_t l)
Packing str header and length.
Definition: pack.hpp:1232
void * allocate_align(size_t size, size_t align=MSGPACK_ZONE_ALIGN)
Definition: cpp03_zone.hpp:256
std::size_t size(T const &t)
Definition: size_equal_only.hpp:24
@ STR
Definition: object_fwd_decl.hpp:38
Definition: adaptor_base.hpp:15
uint32_t checked_get_container_size(T size)
Definition: check_container_size.hpp:55
void operator()(msgpack::object &o, char *v) const
Definition: char_ptr.hpp:79
void operator()(msgpack::object &o, const char *v) const
Definition: char_ptr.hpp:53
void operator()(msgpack::object::with_zone &o, char *v) const
Definition: char_ptr.hpp:72
void operator()(msgpack::object::with_zone &o, const char *v) const
Definition: char_ptr.hpp:41
Definition: adaptor_base.hpp:43
Definition: adaptor_base.hpp:38
packer< Stream > & operator()(packer< Stream > &o, char *v) const
Definition: char_ptr.hpp:65
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const char *v) const
Definition: char_ptr.hpp:31
Definition: adaptor_base.hpp:32
Definition: object.hpp:35
msgpack::zone & zone
Definition: object.hpp:37
const char * ptr
Definition: object_fwd.hpp:34
uint32_t size
Definition: object_fwd.hpp:33
Object class that corresponding to MessagePack format object.
Definition: object_fwd.hpp:75
union_type via
Definition: object_fwd.hpp:93
msgpack::type::object_type type
Definition: object_fwd.hpp:92
msgpack::object_str str
Definition: object_fwd.hpp:87
#define MSGPACK_ZONE_ALIGNOF(type)
Definition: cpp03_zone_decl.hpp:30
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:66