check_container_size.hpp
Go to the documentation of this file.
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2015 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_CHECK_CONTAINER_SIZE_HPP
#define MSGPACK_V1_CHECK_CONTAINER_SIZE_HPP
#include "msgpack/v1/adaptor/check_container_size_decl.hpp"
#include <stdexcept>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
struct container_size_overflow : public std::runtime_error {
explicit container_size_overflow(const std::string& msg)
:std::runtime_error(msg) {}
#if !defined(MSGPACK_USE_CPP03)
explicit container_size_overflow(const char* msg):
std::runtime_error(msg) {}
#endif // !defined(MSGPACK_USE_CPP03)
};
namespace detail {
template <std::size_t N>
inline void check_container_size(std::size_t size) {
if (size > 0xffffffff) throw container_size_overflow("container size overflow");
}
template <>
inline void check_container_size<4>(std::size_t /*size*/) {
}
template <std::size_t N>
inline void check_container_size_for_ext(std::size_t size) {
if (size > 0xffffffff) throw container_size_overflow("container size overflow");
}
template <>
inline void check_container_size_for_ext<4>(std::size_t size) {
if (size > 0xfffffffe) throw container_size_overflow("container size overflow");
}
} // namespace detail
template <typename T>
inline uint32_t checked_get_container_size(T size) {
detail::check_container_size<sizeof(T)>(size);
return static_cast<uint32_t>(size);
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_V1_CHECK_CONTAINER_SIZE_HPP
msgpack::checked_get_container_size
uint32_t checked_get_container_size(T size)
Definition: check_container_size.hpp:55
msgpack::container_size_overflow::container_size_overflow
container_size_overflow(const char *msg)
Definition: check_container_size.hpp:26
check_container_size_decl.hpp
msgpack::detail::check_container_size_for_ext< 4 >
void check_container_size_for_ext< 4 >(std::size_t size)
Definition: check_container_size.hpp:48
msgpack::container_size_overflow::container_size_overflow
container_size_overflow(const std::string &msg)
Definition: check_container_size.hpp:23
msgpack
Definition: adaptor_base.hpp:15
msgpack::type::size
std::size_t size(T const &t)
Definition: size_equal_only.hpp:24
msgpack::detail::check_container_size
void check_container_size(std::size_t size)
Definition: check_container_size.hpp:34
msgpack::container_size_overflow
Definition: check_container_size.hpp:22
MSGPACK_API_VERSION_NAMESPACE
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition: versioning.hpp:58
msgpack::detail::check_container_size< 4 >
void check_container_size< 4 >(std::size_t)
Definition: check_container_size.hpp:39
msgpack::detail::check_container_size_for_ext
void check_container_size_for_ext(std::size_t size)
Definition: check_container_size.hpp:43