Vanetza
 
Loading...
Searching...
No Matches
length_coding.hpp
1#ifndef LENGTH_CODING_HPP_UQ1OIDUN
2#define LENGTH_CODING_HPP_UQ1OIDUN
3
4#include <vanetza/common/byte_buffer.hpp>
5#include <boost/range/iterator_range.hpp>
6#include <cstdint>
7#include <tuple>
8
9namespace vanetza
10{
11namespace security
12{
13namespace v2
14{
15
16/**
17 * Calculate length coding for variable length fields
18 * \param length Data field length in bytes, e.g. size of a buffer
19 * \return byte buffer containing encoded length, prepend to data
20 */
21ByteBuffer encode_length(std::uintmax_t length);
22
23/**
24 * Extract length information
25 * \param buffer Buffer with input data, shall start with first byte of encoded length
26 * \return iterator pointing at start of payload buffer (begin indicates error) and its length
27 */
28std::tuple<ByteBuffer::const_iterator, std::uintmax_t> decode_length(const ByteBuffer& buffer);
29
30/**
31 * Count number of leading one bits
32 * \param a byte
33 * \return number of leadings ones in given byte
34 */
35std::size_t count_leading_ones(std::uint8_t);
36
37/**
38 * Determines the number of bytes, needed to store a given size
39 * \param size
40 * \return number of bytes needed to store length
41 */
42std::size_t length_coding_size(std::uintmax_t);
43
44} // namespace v2
45} // namespace security
46} // namespace vanetza
47
48#endif /* LENGTH_CODING_HPP_UQ1OIDUN */
49