protozero 1.7.1
Minimalistic protocol buffer decoder and encoder in C++.
Loading...
Searching...
No Matches
buffer_vector.hpp
Go to the documentation of this file.
1#ifndef PROTOZERO_BUFFER_VECTOR_HPP
2#define PROTOZERO_BUFFER_VECTOR_HPP
3
4/*****************************************************************************
5
6protozero - Minimalistic protocol buffer decoder and encoder in C++.
7
8This file is from https://github.com/mapbox/protozero where you can find more
9documentation.
10
11*****************************************************************************/
12
20#include "buffer_tmpl.hpp"
21#include "config.hpp"
22
23#include <cstddef>
24#include <iterator>
25#include <vector>
26
27namespace protozero {
28
29// Implementation of buffer customizations points for std::vector<char>
30
32template <>
33struct buffer_customization<std::vector<char>> {
34
35 static std::size_t size(const std::vector<char>* buffer) noexcept {
36 return buffer->size();
37 }
38
39 static void append(std::vector<char>* buffer, const char* data, std::size_t count) {
40 buffer->insert(buffer->end(), data, data + count);
41 }
42
43 static void append_zeros(std::vector<char>* buffer, std::size_t count) {
44 buffer->insert(buffer->end(), count, '\0');
45 }
46
47 static void resize(std::vector<char>* buffer, std::size_t size) {
48 protozero_assert(size < buffer->size());
49 buffer->resize(size);
50 }
51
52 static void reserve_additional(std::vector<char>* buffer, std::size_t size) {
53 buffer->reserve(buffer->size() + size);
54 }
55
56 static void erase_range(std::vector<char>* buffer, std::size_t from, std::size_t to) {
57 protozero_assert(from <= buffer->size());
58 protozero_assert(to <= buffer->size());
59 protozero_assert(from <= to);
60 buffer->erase(std::next(buffer->begin(), static_cast<std::string::iterator::difference_type>(from)),
61 std::next(buffer->begin(), static_cast<std::string::iterator::difference_type>(to)));
62 }
63
64 static char* at_pos(std::vector<char>* buffer, std::size_t pos) {
65 protozero_assert(pos <= buffer->size());
66 return (&*buffer->begin()) + pos;
67 }
68
69 static void push_back(std::vector<char>* buffer, char ch) {
70 buffer->push_back(ch);
71 }
72
73};
75
76} // namespace protozero
77
78#endif // PROTOZERO_BUFFER_VECTOR_HPP
Contains the customization points for buffer implementations.
Contains macro checks for different configurations.
All parts of the protozero header-only library are in this namespace.
Definition basic_pbf_builder.hpp:24