EmbeddedProto  2.0.0
EmbeddedProto is a C++ Protocol Buffer implementation specifically suitable for microcontrollers.
ReadBufferSection.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 Embedded AMS B.V. - All Rights Reserved
3  *
4  * This file is part of Embedded Proto.
5  *
6  * Embedded Proto is open source software: you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as published
8  * by the Free Software Foundation, version 3 of the license.
9  *
10  * Embedded Proto is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Embedded Proto. If not, see <https://www.gnu.org/licenses/>.
17  *
18  * For commercial and closed source application please visit:
19  * <https://EmbeddedProto.com/license/>.
20  *
21  * Embedded AMS B.V.
22  * Info:
23  * info at EmbeddedProto dot com
24  *
25  * Postal address:
26  * Johan Huizingalaan 763a
27  * 1066 VH, Amsterdam
28  * the Netherlands
29  */
30 
31 #ifndef _READ_BUFFER_SECTION_H_
32 #define _READ_BUFFER_SECTION_H_
33 
34 #include "ReadBufferInterface.h"
35 
36 #include <cstdint>
37 
38 
39 namespace EmbeddedProto
40 {
42 
50  {
51  public:
52 
54  ReadBufferSection() = delete;
55 
57 
61  ReadBufferSection(ReadBufferInterface& buffer, const uint32_t size);
62 
63  virtual ~ReadBufferSection() = default;
64 
65 
67  uint32_t get_size() const override;
68 
70 
73  uint32_t get_max_size() const override;
74 
76 
79  bool peek(uint8_t& byte) const override;
80 
82 
85  void advance() override;
86 
88 
91  void advance(const uint32_t N) override;
92 
94 
97  bool pop(uint8_t& byte) override;
98 
99  private:
100 
102  ReadBufferInterface& buffer_;
103 
105  uint32_t size_;
106 
108  const uint32_t max_size_;
109  };
110 
111 } // End of namespace EmbeddedProto
112 
113 #endif // _READ_BUFFER_SECTION_H_
EmbeddedProto::ReadBufferSection::ReadBufferSection
ReadBufferSection()=delete
Explicitly delete the default constructor in favor of the one with parameters.
EmbeddedProto::ReadBufferSection::advance
void advance() override
Decrement the size and call advance on the parent buffer.
Definition: ReadBufferSection.cpp:67
EmbeddedProto::ReadBufferInterface
The pure virtual definition of a message buffer to read from.
Definition: ReadBufferInterface.h:43
EmbeddedProto::ReadBufferSection::get_max_size
uint32_t get_max_size() const override
Obtain the total number of bytes which can at most be stored in the buffer.
Definition: ReadBufferSection.cpp:52
EmbeddedProto
Definition: Errors.h:34
ReadBufferInterface.h
EmbeddedProto::ReadBufferSection::peek
bool peek(uint8_t &byte) const override
Expose the function of the parent buffer.
Definition: ReadBufferSection.cpp:57
EmbeddedProto::ReadBufferSection::~ReadBufferSection
virtual ~ReadBufferSection()=default
EmbeddedProto::ReadBufferSection
This is a wrapper around a ReadBufferInterface only exposing a given number of bytes.
Definition: ReadBufferSection.h:49
EmbeddedProto::ReadBufferSection::pop
bool pop(uint8_t &byte) override
Decrement the size and pop the next byte from the parent buffer.
Definition: ReadBufferSection.cpp:86
EmbeddedProto::ReadBufferSection::get_size
uint32_t get_size() const override
Return the number of bytes remaining.
Definition: ReadBufferSection.cpp:47