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-2016 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_V1_TYPE_V4RAW_HPP
11 #define MSGPACK_V1_TYPE_V4RAW_HPP
12 
14 #include <cstring>
15 #include <string>
16 
17 namespace msgpack {
18 
22 
23 namespace type {
24 
25 struct v4raw_ref {
27  v4raw_ref(const char* p, uint32_t s) : size(s), ptr(p) {}
28 
29  uint32_t size;
30  const char* ptr;
31 
32  std::string str() const { return std::string(ptr, size); }
33 
34  bool operator== (const v4raw_ref& x) const
35  {
36  return size == x.size && (size == 0 || std::memcmp(ptr, x.ptr, size) == 0);
37  }
38 
39  bool operator!= (const v4raw_ref& x) const
40  {
41  return !(*this == x);
42  }
43 
44  bool operator< (const v4raw_ref& x) const
45  {
46  if(size == x.size) { return std::memcmp(ptr, x.ptr, size) < 0; }
47  else { return size < x.size; }
48  }
49 
50  bool operator> (const v4raw_ref& x) const
51  {
52  if(size == x.size) { return std::memcmp(ptr, x.ptr, size) > 0; }
53  else { return size > x.size; }
54  }
55 };
56 
57 } // namespace type
58 
59 namespace adaptor {
60 
61 template <>
62 struct convert<type::v4raw_ref> {
64  if(o.type != msgpack::type::STR) { throw msgpack::type_error(); }
65  v.ptr = o.via.str.ptr;
66  v.size = o.via.str.size;
67  return o;
68  }
69 };
70 
71 template <>
72 struct pack<type::v4raw_ref> {
73  template <typename Stream>
75  o.pack_v4raw(v.size);
76  o.pack_v4raw_body(v.ptr, v.size);
77  return o;
78  }
79 };
80 
81 template <>
82 struct object<type::v4raw_ref> {
83  void operator()(msgpack::object& o, const type::v4raw_ref& v) const {
85  o.via.str.ptr = v.ptr;
86  o.via.str.size = v.size;
87  }
88 };
89 
90 template <>
91 struct object_with_zone<type::v4raw_ref> {
93  static_cast<msgpack::object&>(o) << v;
94  }
95 };
96 
97 } // namespace adaptor
98 
100 } // MSGPACK_API_VERSION_NAMESPACE(v1)
102 
103 } // namespace msgpack
104 
105 #endif // MSGPACK_V1_TYPE_V4RAW_HPP
The class template that supports continuous packing.
Definition: pack.hpp:33
packer< Stream > & pack_v4raw(uint32_t l)
Packing raw (v4) header and length.
Definition: pack.hpp:1264
packer< Stream > & pack_v4raw_body(const char *b, uint32_t l)
Packing raw (v4) body.
Definition: pack.hpp:1283
Definition: object_fwd.hpp:231
@ STR
Definition: object_fwd_decl.hpp:38
Definition: adaptor_base.hpp:15
msgpack::object const & operator()(msgpack::object const &o, type::v4raw_ref &v) const
Definition: v4raw.hpp:63
Definition: adaptor_base.hpp:27
void operator()(msgpack::object &o, const type::v4raw_ref &v) const
Definition: v4raw.hpp:83
void operator()(msgpack::object::with_zone &o, const type::v4raw_ref &v) const
Definition: v4raw.hpp:92
Definition: adaptor_base.hpp:43
Definition: adaptor_base.hpp:38
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::v4raw_ref &v) const
Definition: v4raw.hpp:74
Definition: adaptor_base.hpp:32
Definition: object.hpp:35
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
Definition: v4raw.hpp:25
bool operator!=(const v4raw_ref &x) const
Definition: v4raw.hpp:39
v4raw_ref(const char *p, uint32_t s)
Definition: v4raw.hpp:27
std::string str() const
Definition: v4raw.hpp:32
bool operator>(const v4raw_ref &x) const
Definition: v4raw.hpp:50
uint32_t size
Definition: v4raw.hpp:29
const char * ptr
Definition: v4raw.hpp:30
v4raw_ref()
Definition: v4raw.hpp:26
bool operator<(const v4raw_ref &x) const
Definition: v4raw.hpp:44
bool operator==(const v4raw_ref &x) const
Definition: v4raw.hpp:34
msgpack::object_str str
Definition: object_fwd.hpp:87
#define MSGPACK_NULLPTR
Definition: cpp_config_decl.hpp:85
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:66