v4raw.hpp
Go to the documentation of this file.
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef MSGPACK_V1_TYPE_V4RAW_HPP
#define MSGPACK_V1_TYPE_V4RAW_HPP
#include "msgpack/v1/adaptor/v4raw_decl.hpp"
#include <cstring>
#include <string>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
namespace type {
struct v4raw_ref {
v4raw_ref() : size(0), ptr(MSGPACK_NULLPTR) {}
v4raw_ref(const char* p, uint32_t s) : size(s), ptr(p) {}
uint32_t size;
const char* ptr;
std::string str() const { return std::string(ptr, size); }
bool operator== (const v4raw_ref& x) const
{
return size == x.size && std::memcmp(ptr, x.ptr, size) == 0;
}
bool operator!= (const v4raw_ref& x) const
{
return !(*this == x);
}
bool operator< (const v4raw_ref& x) const
{
if(size == x.size) { return std::memcmp(ptr, x.ptr, size) < 0; }
else { return size < x.size; }
}
bool operator> (const v4raw_ref& x) const
{
if(size == x.size) { return std::memcmp(ptr, x.ptr, size) > 0; }
else { return size > x.size; }
}
};
} // namespace type
namespace adaptor {
template <>
struct convert<type::v4raw_ref> {
msgpack::object const& operator()(msgpack::object const& o, type::v4raw_ref& v) const {
if(o.type != msgpack::type::STR) { throw msgpack::type_error(); }
v.ptr = o.via.str.ptr;
v.size = o.via.str.size;
return o;
}
};
template <>
struct pack<type::v4raw_ref> {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::v4raw_ref& v) const {
o.pack_v4raw(v.size);
o.pack_v4raw_body(v.ptr, v.size);
return o;
}
};
template <>
struct object<type::v4raw_ref> {
void operator()(msgpack::object& o, const type::v4raw_ref& v) const {
o.type = msgpack::type::STR;
o.via.str.ptr = v.ptr;
o.via.str.size = v.size;
}
};
template <>
struct object_with_zone<type::v4raw_ref> {
void operator()(msgpack::object::with_zone& o, const type::v4raw_ref& v) const {
static_cast<msgpack::object&>(o) << v;
}
};
} // namespace adaptor
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_V1_TYPE_V4RAW_HPP
msgpack::type::STR
Definition: object_fwd_decl.hpp:39
msgpack::packer::pack_v4raw
packer< Stream > & pack_v4raw(uint32_t l)
Packing raw (v4) header and length.
Definition: pack.hpp:1229
msgpack::type::v4raw_ref::v4raw_ref
v4raw_ref(const char *p, uint32_t s)
Definition: v4raw.hpp:27
msgpack::adaptor::convert< type::v4raw_ref >::operator()
msgpack::object const & operator()(msgpack::object const &o, type::v4raw_ref &v) const
Definition: v4raw.hpp:63
msgpack::type::v4raw_ref::size
uint32_t size
Definition: v4raw.hpp:29
msgpack::type::v4raw_ref::operator<
bool operator<(const v4raw_ref &x) const
Definition: v4raw.hpp:44
msgpack::object::via
union_type via
Definition: object_fwd.hpp:93
msgpack::type::v4raw_ref::operator>
bool operator>(const v4raw_ref &x) const
Definition: v4raw.hpp:50
msgpack::type::v4raw_ref
Definition: v4raw.hpp:25
v4raw_decl.hpp
msgpack
Definition: adaptor_base.hpp:15
msgpack::adaptor::object< type::v4raw_ref >::operator()
void operator()(msgpack::object &o, const type::v4raw_ref &v) const
Definition: v4raw.hpp:83
msgpack::object_str::ptr
const char * ptr
Definition: object_fwd.hpp:34
msgpack::object::with_zone
Definition: object.hpp:34
msgpack::adaptor::object_with_zone< type::v4raw_ref >::operator()
void operator()(msgpack::object::with_zone &o, const type::v4raw_ref &v) const
Definition: v4raw.hpp:92
msgpack::adaptor::object_with_zone
Definition: adaptor_base.hpp:43
msgpack::type::v4raw_ref::str
std::string str() const
Definition: v4raw.hpp:32
msgpack::type::v4raw_ref::operator!=
bool operator!=(const v4raw_ref &x) const
Definition: v4raw.hpp:39
msgpack::type_error
Definition: object_fwd.hpp:236
msgpack::adaptor::pack
Definition: adaptor_base.hpp:32
msgpack::type::v4raw_ref::v4raw_ref
v4raw_ref()
Definition: v4raw.hpp:26
msgpack::object::union_type::str
msgpack::object_str str
Definition: object_fwd.hpp:87
msgpack::adaptor::pack< type::v4raw_ref >::operator()
msgpack::packer< Stream > & operator()(msgpack::packer< Stream > &o, const type::v4raw_ref &v) const
Definition: v4raw.hpp:74
msgpack::object
Object class that corresponding to MessagePack format object.
Definition: object_fwd.hpp:75
msgpack::packer::pack_v4raw_body
packer< Stream > & pack_v4raw_body(const char *b, uint32_t l)
Packing raw (v4) body.
Definition: pack.hpp:1248
msgpack::object::type
msgpack::type::object_type type
Definition: object_fwd.hpp:92
MSGPACK_API_VERSION_NAMESPACE
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:58
msgpack::type::v4raw_ref::operator==
bool operator==(const v4raw_ref &x) const
Definition: v4raw.hpp:34
msgpack::object_str::size
uint32_t size
Definition: object_fwd.hpp:33
msgpack::type::v4raw_ref::ptr
const char * ptr
Definition: v4raw.hpp:30
msgpack::adaptor::object
Definition: adaptor_base.hpp:38
msgpack::packer
The class template that supports continuous packing.
Definition: adaptor_base_decl.hpp:24
MSGPACK_NULLPTR
#define MSGPACK_NULLPTR
Definition: cpp_config_decl.hpp:35
msgpack::adaptor::convert
Definition: adaptor_base.hpp:27