MessagePack for C++
v4raw.hpp
Go to the documentation of this file.
1 //
2 // MessagePack for C++ static resolution routine
3 //
4 // Copyright (C) 2008-2015 FURUHASHI Sadayuki and 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_TYPE_V4RAW_HPP
11 #define MSGPACK_TYPE_V4RAW_HPP
12 
13 #include "msgpack/versioning.hpp"
15 #include <cstring>
16 #include <string>
17 
18 namespace msgpack {
19 
23 
24 namespace type {
25 
26 struct v4raw_ref {
27  v4raw_ref() : size(0), ptr(nullptr) {}
28  v4raw_ref(const char* p, uint32_t s) : size(s), ptr(p) {}
29 
30  uint32_t size;
31  const char* ptr;
32 
33  std::string str() const { return std::string(ptr, size); }
34 
35  bool operator== (const v4raw_ref& x) const
36  {
37  return size == x.size && std::memcmp(ptr, x.ptr, size) == 0;
38  }
39 
40  bool operator!= (const v4raw_ref& x) const
41  {
42  return !(*this == x);
43  }
44 
45  bool operator< (const v4raw_ref& x) const
46  {
47  if(size == x.size) { return std::memcmp(ptr, x.ptr, size) < 0; }
48  else { return size < x.size; }
49  }
50 
51  bool operator> (const v4raw_ref& x) const
52  {
53  if(size == x.size) { return std::memcmp(ptr, x.ptr, size) > 0; }
54  else { return size > x.size; }
55  }
56 };
57 
58 } // namespace type
59 
60 namespace adaptor {
61 
62 template <>
65  if(o.type != msgpack::type::STR) { throw msgpack::type_error(); }
66  v.ptr = o.via.str.ptr;
67  v.size = o.via.str.size;
68  return o;
69  }
70 };
71 
72 template <>
74  template <typename Stream>
76  o.pack_v4raw(v.size);
77  o.pack_v4raw_body(v.ptr, v.size);
78  return o;
79  }
80 };
81 
82 template <>
86  o.via.str.ptr = v.ptr;
87  o.via.str.size = v.size;
88  }
89 };
90 
91 template <>
94  static_cast<msgpack::object&>(o) << v;
95  }
96 };
97 
98 } // namespace adaptor
99 
101 } // MSGPACK_API_VERSION_NAMESPACE(v1)
103 
104 } // namespace msgpack
105 
106 #endif // MSGPACK_TYPE_V4RAW_HPP
Definition: object_fwd.hpp:37
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:58
packer< Stream > & pack_v4raw(uint32_t l)
Packing raw (v4) header and length.
Definition: pack.hpp:1232
v4raw_ref(const char *p, uint32_t s)
Definition: v4raw.hpp:28
uint32_t size
Definition: v4raw.hpp:30
bool operator<(const v4raw_ref &x) const
Definition: v4raw.hpp:45
union_type via
Definition: object_fwd.hpp:123
bool operator>(const v4raw_ref &x) const
Definition: v4raw.hpp:51
Definition: v4raw.hpp:26
Definition: adaptor_base.hpp:15
const char * ptr
Definition: object_fwd.hpp:61
Definition: object_fwd.hpp:260
void operator()(msgpack::object::with_zone &o, const msgpack::type::v4raw_ref &v) const
Definition: v4raw.hpp:93
Definition: adaptor_base.hpp:45
std::string str() const
Definition: v4raw.hpp:33
bool operator!=(const v4raw_ref &x) const
Definition: v4raw.hpp:40
Definition: object_fwd.hpp:253
Definition: adaptor_base.hpp:34
v4raw_ref()
Definition: v4raw.hpp:27
msgpack::object_str str
Definition: object_fwd.hpp:117
msgpack::object const & operator()(msgpack::object const &o, msgpack::type::v4raw_ref &v) const
Definition: v4raw.hpp:64
Object class that corresponding to MessagePack format object.
Definition: object_fwd.hpp:106
packer< Stream > & pack_v4raw_body(const char *b, uint32_t l)
Packing raw (v4) body.
Definition: pack.hpp:1251
msgpack::type::object_type type
Definition: object_fwd.hpp:122
bool operator==(const v4raw_ref &x) const
Definition: v4raw.hpp:35
uint32_t size
Definition: object_fwd.hpp:60
#define nullptr
Definition: cpp_config.hpp:31
const char * ptr
Definition: v4raw.hpp:31
Definition: adaptor_base.hpp:40
The class template that supports continuous packing.
Definition: adaptor_base.hpp:22
Definition: adaptor_base.hpp:29
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const msgpack::type::v4raw_ref &v) const
Definition: v4raw.hpp:75
void operator()(msgpack::object &o, const msgpack::type::v4raw_ref &v) const
Definition: v4raw.hpp:84