MessagePack for C++
Loading...
Searching...
No Matches
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
17
18#include <cstring>
19
20namespace msgpack {
21
25
26namespace adaptor {
27
28template <>
29struct 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
39template <>
41 void operator()(msgpack::object::with_zone& o, const char* v) const {
42 uint32_t size = checked_get_container_size(std::strlen(v));
43 o.type = msgpack::type::STR;
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
51template <>
52struct object<const char*> {
53 void operator()(msgpack::object& o, const char* v) const {
54 uint32_t size = checked_get_container_size(std::strlen(v));
55 o.type = msgpack::type::STR;
56 o.via.str.ptr = v;
57 o.via.str.size = size;
58 }
59};
60
61
62template <>
63struct pack<char*> {
64 template <typename Stream>
68};
69
70template <>
76
77template <>
78struct object<char*> {
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
Definition adaptor_base.hpp:15
uint32_t checked_get_container_size(T size)
Definition check_container_size.hpp:55
Definition adaptor_base.hpp:27
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
Object class that corresponding to MessagePack format object.
Definition object_fwd.hpp:75
#define MSGPACK_ZONE_ALIGNOF(type)
Definition cpp03_zone_decl.hpp:30
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition versioning.hpp:66