Vanetza
 
Loading...
Searching...
No Matches
int_x.hpp
1#ifndef INT_X_HPP_RW3TJBBI
2#define INT_X_HPP_RW3TJBBI
3
4#include <vanetza/common/byte_buffer.hpp>
5#include <vanetza/security/v2/serialization.hpp>
6#include <boost/operators.hpp>
7#include <boost/optional.hpp>
8#include <cstdint>
9
10namespace vanetza
11{
12namespace security
13{
14namespace v2
15{
16
17/// IntX specified in TS 103 097 v1.2.1, section 4.2.1
18class IntX :
19 public boost::equality_comparable<IntX>,
20 public boost::equality_comparable<IntX, std::uintmax_t>
21{
22public:
23 using integer_type = std::uintmax_t;
24 constexpr IntX() : m_value(0) {}
25 constexpr explicit IntX(integer_type x) : m_value(x) {}
26
27 void set(integer_type x);
28 constexpr integer_type get() const { return m_value; }
29
30 constexpr bool operator==(const IntX& other) const
31 {
32 return m_value == other.m_value;
33 }
34
35 constexpr bool operator==(integer_type other) const
36 {
37 return m_value == other;
38 }
39
40 ByteBuffer encode() const;
41 static boost::optional<IntX> decode(const ByteBuffer&);
42
43private:
44 integer_type m_value;
45};
46
47/**
48 * \brief Serializes an IntX into a binary archive
49 * \param ar to serialize in
50 * \param intx to serialize
51 */
52void serialize(OutputArchive&, const IntX&);
53
54/**
55 * \brief Deserializes an IntX from a binary archive
56 * \param ar with a serialized IntX at the beginning
57 * \param intx to deserialize
58 * \return size of the deserialized IntX
59 */
60size_t deserialize(InputArchive&, IntX&);
61
62/**
63 * \brief Calculates size of an IntX
64 * \param intx
65 * \return number of octets needed to serialize the IntX
66 */
67size_t get_size(IntX);
68
69} // namespace v2
70} // namespace security
71} // namespace vanetza
72
73#endif /* INT_X_HPP_RW3TJBBI */
IntX specified in TS 103 097 v1.2.1, section 4.2.1.
Definition: int_x.hpp:21