Line data Source code
1 : /***************************************************************************\
2 : * Name : serialize library for protobuf *
3 : * Description : field attributes *
4 : * Author : antonin.kriz@gmail.com *
5 : * ------------------------------------------------------------------------- *
6 : * This is free software; you can redistribute it and/or modify it under the *
7 : * terms of the MIT license. A copy of the license can be found in the file *
8 : * "LICENSE" at the root of this distribution. *
9 : \***************************************************************************/
10 :
11 : #pragma once
12 :
13 : #include <cstddef>
14 : #include <stdexcept>
15 :
16 : namespace spb::json::detail
17 : {
18 : struct field_attributes
19 : {
20 : size_t max_count = 0;
21 : size_t max_size = 0;
22 : };
23 :
24 530 : inline void check_size(size_t size, size_t max_size)
25 : {
26 530 : if (size > max_size) [[unlikely]]
27 50 : throw std::length_error("field is too large");
28 480 : }
29 :
30 : } // namespace spb::json::detail
|