File: inbuffer.h

package info (click to toggle)
amqp-cpp 4.3.27-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,384 kB
  • sloc: cpp: 10,021; ansic: 191; makefile: 95
file content (143 lines) | stat: -rw-r--r-- 2,727 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**
 *  InBuffer.h
 *
 *  The InBuffer class is a wrapper around a data buffer and that adds
 *  some safety checks so that the rest of the library can safely read
 *  from it.
 *
 *  This is a class that is used internally by the AMQP library. As a user
 *  of this library, you normally do not have to instantiate it. However,
 *  if you do want to store or safe messages yourself, it sometimes can
 *  be useful to implement it.
 *
 *  @copyright 2014 - 2020 Copernica BV
 */

/**
 *  Include guard
 */
#pragma once

/**
 *  Dependencies
 */
#include <cstdint>

/**
 *  Set up namespace
 */
namespace AMQP {

/**
 *  Forward declarations
 */
class Buffer;

/**
 *  Class definition
 */
class InBuffer
{
protected:
    /**
     *  The buffer we are reading from
     *  @var    Buffer
     */
    const Buffer &_buffer;

    /**
     *  Number of bytes already processed
     *  @var    size_t
     */
    size_t _skip = 0;

public:
    /**
     *  Constructor
     *  @param  buffer      Binary buffer
     */
    InBuffer(const Buffer &buffer) : _buffer(buffer) {}

    /**
     *  Destructor
     */
    virtual ~InBuffer() {}

    /**
     *  Read the next uint8_t from the buffer
     *  @return uint8_t         value read
     */
    uint8_t nextUint8();

    /**
     *  Read the next int8_t from the buffer
     *  @return int8_t          value read
     */
    int8_t nextInt8();

    /**
     *  Read the next uint16_t from the buffer
     *  @return uint16_t        value read
     */
    uint16_t nextUint16();

    /**
     *  Read the next int16_t from the buffer
     *  @return int16_t     value read
     */
    int16_t nextInt16();

    /**
     *  Read the next uint32_t from the buffer
     *  @return uint32_t        value read
     */
    uint32_t nextUint32();

    /**
     *  Read the next int32_t from the buffer
     *  @return int32_t     value read
     */
    int32_t nextInt32();

    /**
     *  Read the next uint64_t from the buffer
     *  @return uint64_t        value read
     */
    uint64_t nextUint64();

    /**
     *  Read the next int64_t from the buffer
     *  @return int64_t     value read
     */
    int64_t nextInt64();

    /**
     *  Read a float from the buffer
     *  @return float       float read from buffer.
     */
    float nextFloat();

    /**
     *  Read a double from the buffer
     *  @return double      double read from buffer
     */
    double nextDouble();

    /**
     *  Get a pointer to the next binary buffer of a certain size
     *  @param  size
     *  @return char*
     */
    const char *nextData(size_t size);

    /**
     *  The checker may access private data
     */
    friend class BufferCheck;

};

/**
 *  End of namespace
 */
}