summaryrefslogtreecommitdiffstats
path: root/ext/protozero/include/protozero/exception.hpp
blob: a3cd0f15db74928dba3a322e33c08215dbef9d4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef PROTOZERO_EXCEPTION_HPP
#define PROTOZERO_EXCEPTION_HPP

/*****************************************************************************

protozero - Minimalistic protocol buffer decoder and encoder in C++.

This file is from https://github.com/mapbox/protozero where you can find more
documentation.

*****************************************************************************/

/**
 * @file exception.hpp
 *
 * @brief Contains the exceptions used in the protozero library.
 */

#include <exception>

/**
 * @brief All parts of the protozero header-only library are in this namespace.
 */
namespace protozero {

/**
 * All exceptions explicitly thrown by the functions of the protozero library
 * derive from this exception.
 */
struct exception : std::exception {
    /// Returns the explanatory string.
    const char* what() const noexcept override {
        return "pbf exception";
    }
};

/**
 * This exception is thrown when parsing a varint thats larger than allowed.
 * This should never happen unless the data is corrupted.
 */
struct varint_too_long_exception : exception {
    /// Returns the explanatory string.
    const char* what() const noexcept override {
        return "varint too long exception";
    }
};

/**
 * This exception is thrown when the wire type of a pdf field is unknown.
 * This should never happen unless the data is corrupted.
 */
struct unknown_pbf_wire_type_exception : exception {
    /// Returns the explanatory string.
    const char* what() const noexcept override {
        return "unknown pbf field type exception";
    }
};

/**
 * This exception is thrown when we are trying to read a field and there
 * are not enough bytes left in the buffer to read it. Almost all functions
 * of the pbf_reader class can throw this exception.
 *
 * This should never happen unless the data is corrupted or you have
 * initialized the pbf_reader object with incomplete data.
 */
struct end_of_buffer_exception : exception {
    /// Returns the explanatory string.
    const char* what() const noexcept override {
        return "end of buffer exception";
    }
};

/**
 * This exception is thrown when a tag has an invalid value. Tags must be
 * unsigned integers between 1 and 2^29-1. Tags between 19000 and 19999 are
 * not allowed. See
 * https://developers.google.com/protocol-buffers/docs/proto#assigning-tags
 */
struct invalid_tag_exception : exception {
    /// Returns the explanatory string.
    const char* what() const noexcept override {
        return "invalid tag exception";
    }
};

/**
 * This exception is thrown when a length field of a packed repeated field is
 * invalid. For fixed size types the length must be a multiple of the size of
 * the type.
 */
struct invalid_length_exception : exception {
    /// Returns the explanatory string.
    const char* what() const noexcept override {
        return "invalid length exception";
    }
};

} // end namespace protozero

#endif // PROTOZERO_EXCEPTION_HPP