MessagePack for C++
Toggle main menu visibility
Loading...
Searching...
No Matches
msgpack
v1
adaptor
check_container_size.hpp
Go to the documentation of this file.
1
//
2
// MessagePack for C++ static resolution routine
3
//
4
// Copyright (C) 2015 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_CHECK_CONTAINER_SIZE_HPP
11
#define MSGPACK_V1_CHECK_CONTAINER_SIZE_HPP
12
13
#include "
msgpack/v1/adaptor/check_container_size_decl.hpp
"
14
#include <stdexcept>
15
16
namespace
msgpack
{
17
19
MSGPACK_API_VERSION_NAMESPACE
(v1) {
21
22
struct
container_size_overflow
:
public
std::runtime_error {
23
explicit
container_size_overflow
(
const
std::string& msg)
24
:std::runtime_error(msg) {}
25
#if !defined(MSGPACK_USE_CPP03)
26
explicit
container_size_overflow
(
const
char
* msg):
27
std::runtime_error(msg) {}
28
#endif
// !defined(MSGPACK_USE_CPP03)
29
};
30
31
namespace
detail
{
32
33
template
<std::
size_t
N>
34
inline
void
check_container_size
(std::size_t size) {
35
if
(size > 0xffffffff)
throw
container_size_overflow
(
"container size overflow"
);
36
}
37
38
template
<>
39
inline
void
check_container_size<4>
(std::size_t
/*size*/
) {
40
}
41
42
template
<std::
size_t
N>
43
inline
void
check_container_size_for_ext
(std::size_t size) {
44
if
(size > 0xffffffff)
throw
container_size_overflow
(
"container size overflow"
);
45
}
46
47
template
<>
48
inline
void
check_container_size_for_ext<4>
(std::size_t size) {
49
if
(size > 0xfffffffe)
throw
container_size_overflow
(
"container size overflow"
);
50
}
51
52
}
// namespace detail
53
54
template
<
typename
T>
55
inline
uint32_t
checked_get_container_size
(T size) {
56
detail::check_container_size<sizeof(T)>
(
static_cast<
std::size_t
>
(size));
57
return
static_cast<
uint32_t
>
(size);
58
}
59
60
62
}
// MSGPACK_API_VERSION_NAMESPACE(v1)
64
65
}
// namespace msgpack
66
67
#endif
// MSGPACK_V1_CHECK_CONTAINER_SIZE_HPP
msgpack::detail
Definition
check_container_size.hpp:31
msgpack::detail::check_container_size
void check_container_size(std::size_t size)
Definition
check_container_size.hpp:34
msgpack::detail::check_container_size_for_ext
void check_container_size_for_ext(std::size_t size)
Definition
check_container_size.hpp:43
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< 4 >
void check_container_size_for_ext< 4 >(std::size_t size)
Definition
check_container_size.hpp:48
msgpack
Definition
adaptor_base.hpp:15
msgpack::checked_get_container_size
uint32_t checked_get_container_size(T size)
Definition
check_container_size.hpp:55
msgpack::container_size_overflow
Definition
check_container_size.hpp:22
msgpack::container_size_overflow::container_size_overflow
container_size_overflow(const std::string &msg)
Definition
check_container_size.hpp:23
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_API_VERSION_NAMESPACE
#define MSGPACK_API_VERSION_NAMESPACE(ns)
Definition
versioning.hpp:66
Generated by
1.17.0