ReadBuffer.hpp
Go to the documentation of this file.
1 // Copyright (C) 2021 COGIP Robotics association <cogip35@gmail.com>
2 // This file is subject to the terms and conditions of the GNU Lesser
3 // General Public License v2.1. See the file LICENSE in the top level
4 // directory for more details.
5 
12 
13 #pragma once
14 
15 #include <cstdint>
16 #include <cstddef>
17 #include "canpb.hpp"
18 #include "ReadBufferInterface.h"
19 
21 #define CANPB_BASE64_DECODE_BUFFER_SIZE (CANPB_INPUT_MESSAGE_LENGTH_MAX * 2)
22 
23 namespace cogip {
24 
25 namespace canpb {
26 
28 class ReadBuffer : public EmbeddedProto::ReadBufferInterface
29 {
30 public:
32  ReadBuffer();
33 
34  ~ReadBuffer() override = default;
35 
36  uint32_t get_size() const override;
37 
38  uint32_t get_max_size() const override;
39 
40  bool peek(uint8_t &byte) const override;
41 
42  bool advance() override;
43 
44  bool advance(const uint32_t n) override;
45 
46  bool pop(uint8_t &byte) override;
47 
49  uint8_t * get_data_array();
50 
52  uint32_t & get_bytes_written();
53 
55  void clear();
56 
58  bool push(uint8_t &byte);
59 
62  size_t base64_decode();
63 
65  uint8_t * get_base64_data();
66 
67 private:
69  uint8_t data_[CANPB_INPUT_MESSAGE_LENGTH_MAX];
71  uint8_t base64_data_[CANPB_BASE64_DECODE_BUFFER_SIZE];
73  uint32_t write_index_;
75  uint32_t read_index_;
76 };
77 
78 } // namespace canpb
79 
80 } // namespace cogip
81 
cogip::canpb::ReadBuffer::clear
void clear()
Clear all indices, in effect allowing the data to be overwritten.
cogip::canpb::ReadBuffer::get_base64_data
uint8_t * get_base64_data()
Return a pointer to the data array.
cogip::canpb::ReadBuffer::ReadBuffer
ReadBuffer()
Class constructor.
cogip::canpb::ReadBuffer::push
bool push(uint8_t &byte)
Push new data into the buffer.
cogip::canpb::ReadBuffer
ReadBuffer class used to decode Protobuf messages.
Definition: ReadBuffer.hpp:28
cogip
Differential drive controller.
Definition: Coords.hpp:16
cogip::canpb::ReadBuffer::base64_decode
size_t base64_decode()
Decode the data buffer from base64 before deserialization.
canpb.hpp
CANPB_BASE64_DECODE_BUFFER_SIZE
#define CANPB_BASE64_DECODE_BUFFER_SIZE
Size of the base64 decoding buffer.
Definition: ReadBuffer.hpp:21
CANPB_INPUT_MESSAGE_LENGTH_MAX
#define CANPB_INPUT_MESSAGE_LENGTH_MAX
max incoming message length
Definition: canpb.hpp:25
cogip::canpb::ReadBuffer::get_bytes_written
uint32_t & get_bytes_written()
Return a non constant reference to the number of bytes written to the data array.
cogip::canpb::ReadBuffer::get_data_array
uint8_t * get_data_array()
Return a pointer to the data array.