Skip to content

Commit 07a509a

Browse files
committed
Added const char array class template specialization.
1 parent 35483b9 commit 07a509a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

include/msgpack/adaptor/char_ptr.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,39 @@ struct object<char[N]> {
119119
}
120120
};
121121

122+
template <std::size_t N>
123+
struct pack<const char[N]> {
124+
template <typename Stream>
125+
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const char* v) const {
126+
uint32_t size = checked_get_container_size(std::strlen(v));
127+
o.pack_str(size);
128+
o.pack_str_body(v, size);
129+
return o;
130+
}
131+
};
132+
133+
template <std::size_t N>
134+
struct object_with_zone<const char[N]> {
135+
void operator()(msgpack::object::with_zone& o, const char* v) const {
136+
uint32_t size = checked_get_container_size(std::strlen(v));
137+
o.type = msgpack::type::STR;
138+
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
139+
o.via.str.ptr = ptr;
140+
o.via.str.size = size;
141+
std::memcpy(ptr, v, size);
142+
}
143+
};
144+
145+
template <std::size_t N>
146+
struct object<const char[N]> {
147+
void operator()(msgpack::object& o, const char* v) const {
148+
uint32_t size = checked_get_container_size(std::strlen(v));
149+
o.type = msgpack::type::STR;
150+
o.via.str.ptr = v;
151+
o.via.str.size = size;
152+
}
153+
};
154+
122155
} // namespace adaptor
123156

124157
} // MSGPACK_API_VERSION_NAMESPACE(v1)

0 commit comments

Comments
 (0)