AMPS C/C++ Client Class Reference AMPS C/C++ Client Version 5.3.5.1

Buffer.hpp
Go to the documentation of this file.
1 //
3 // Copyright (c) 2010-2025 60East Technologies Inc., All Rights Reserved.
4 //
5 // This computer software is owned by 60East Technologies Inc. and is
6 // protected by U.S. copyright laws and other laws and by international
7 // treaties. This computer software is furnished by 60East Technologies
8 // Inc. pursuant to a written license agreement and may be used, copied,
9 // transmitted, and stored only in accordance with the terms of such
10 // license agreement and with the inclusion of the above copyright notice.
11 // This computer software or any other copies thereof may not be provided
12 // or otherwise made available to any other person.
13 //
14 // U.S. Government Restricted Rights. This computer software: (a) was
15 // developed at private expense and is in all respects the proprietary
16 // information of 60East Technologies Inc.; (b) was not developed with
17 // government funds; (c) is a trade secret of 60East Technologies Inc.
18 // for all purposes of the Freedom of Information Act; and (d) is a
19 // commercial item and thus, pursuant to Section 12.212 of the Federal
20 // Acquisition Regulations (FAR) and DFAR Supplement Section 227.7202,
21 // Government's use, duplication or disclosure of the computer software
22 // is subject to the restrictions set forth by 60East Technologies Inc..
23 //
25
26 #ifndef _BUFFER_H_
27 #define _BUFFER_H_
28
29 #include <amps/ampsplusplus.hpp>
30
34
35 namespace AMPS
36 {
37
40 class Buffer
41 {
42 public:
43 struct ByteArray
44 {
45 char* _data;
46 size_t _len;
47 // If true, the _data buffer is owned and must be deleted
48 bool _owned;
49
50 ByteArray() : _data(0), _len(0), _owned(false) {}
51
52 ByteArray(char* data_, size_t len_, bool owned_)
53 : _data(data_), _len(len_), _owned(owned_) {}
54
55 ByteArray(const ByteArray& rhs_) : _data(rhs_._data), _len(rhs_._len)
56 , _owned(rhs_._owned)
57 {
58 const_cast<ByteArray&>(rhs_)._owned = false;
59 }
60
61 ~ByteArray()
62 {
63 if (_owned)
64 {
65 delete[] _data;
66 }
67 }
68
69 ByteArray& operator=(const ByteArray& rhs_)
70 {
71 _data = rhs_._data;
72 _len = rhs_._len;
73 _owned = rhs_._owned;
74 const_cast<ByteArray&>(rhs_)._owned = false;
75 return *this;
76 }
77 };
78
79 virtual ~Buffer() {}
80
84 virtual size_t getSize() const = 0;
85
89 virtual void setSize(size_t newSize_) = 0;
90
94 virtual size_t getPosition() const = 0;
95
99 virtual void setPosition(size_t position_) = 0;
100
104 virtual void putByte(char byte_) = 0;
105
109 virtual char getByte() = 0;
110
115 virtual void putUint32(amps_uint32_t i_) = 0;
116
121 virtual amps_uint32_t getUint32() = 0;
122
126 virtual void putInt32(amps_int32_t i_) = 0;
127
132 virtual amps_int32_t getInt32() = 0;
133
138 virtual void putSizet(size_t s_) = 0;
139
143 virtual size_t getSizet() = 0;
144
149 virtual void putUint64(amps_uint64_t ui_) = 0;
150
155 virtual amps_uint64_t getUint64() = 0;
156
161 virtual void putInt64(amps_int64_t i_) = 0;
162
167 virtual amps_int64_t getInt64() = 0;
168
174 virtual void putBytes(const char* data_, size_t dataLength_) = 0;
175
180 virtual void putBytes(const ByteArray& bytes_) = 0;
181
186 virtual ByteArray getBytes(size_t numBytes_) = 0;
187
192 virtual void copyBytes(char* buffer_, size_t numBytes_) = 0;
193
199 virtual void zero(size_t offset_, size_t length_) = 0;
200
207 virtual void copyBytes(size_t destination_, size_t source_,
208 size_t number_) = 0;
209 };
210
211 } // end namespace AMPS
212
213 #endif //_BUFFER_H_
214
ampsplusplus.hpp
Core type, function, and class declarations for the AMPS C++ client.
AMPS::Buffer
Abstract base class for implementing a buffer to be used by a StoreImpl for storage of publish messag...
Definition: Buffer.hpp:41
AMPS::Buffer::getByte
virtual char getByte()=0
Get the next byte from the buffer and advance.
AMPS::Buffer::getPosition
virtual size_t getPosition() const =0
Get the current position in the buffer.
AMPS::Buffer::putInt64
virtual void putInt64(amps_int64_t i_)=0
Put an amps_int64_t value into the buffer at the current position and advance past it.
AMPS::Buffer::putUint64
virtual void putUint64(amps_uint64_t ui_)=0
Put an amps_uint64_t value into the buffer at the current position and advance past it.
AMPS::Buffer::putByte
virtual void putByte(char byte_)=0
Put a byte into the buffer at the current position and advance.
AMPS::Buffer::putSizet
virtual void putSizet(size_t s_)=0
Put a size_t value into the buffer at the current position and advance past it.
AMPS::Buffer::putBytes
virtual void putBytes(const ByteArray &bytes_)=0
Put the given bytes into the buffer at the current position and advance past them.
AMPS::Buffer::zero
virtual void zero(size_t offset_, size_t length_)=0
Set the given number of bytes in the buffer to zero starting at the given position.
AMPS::Buffer::putUint32
virtual void putUint32(amps_uint32_t i_)=0
Put an unsigned 32-bit int value into the buffer at the current position and advance past the end of ...
AMPS::Buffer::getSize
virtual size_t getSize() const =0
Get the current size of the Buffer in bytes.
AMPS::Buffer::getUint32
virtual amps_uint32_t getUint32()=0
Get the unsigned 32-bit int value at the current buffer position and advance past it.
AMPS::Buffer::copyBytes
virtual void copyBytes(char *buffer_, size_t numBytes_)=0
Copy the given number of bytes from this buffer to the given buffer.
AMPS::Buffer::setSize
virtual void setSize(size_t newSize_)=0
Set the size for the buffer.
AMPS::Buffer::putBytes
virtual void putBytes(const char *data_, size_t dataLength_)=0
Put the given length of bytes in data into the buffer at the current position and advance past them.
AMPS::Buffer::getSizet
virtual size_t getSizet()=0
Get a size_t value at the current buffer position and advance past it.
AMPS::Buffer::getBytes
virtual ByteArray getBytes(size_t numBytes_)=0
Get the given number of bytes from the buffer.
AMPS::Buffer::putInt32
virtual void putInt32(amps_int32_t i_)=0
Put a 32-bit int value into the buffer and advance past it.
AMPS::Buffer::copyBytes
virtual void copyBytes(size_t destination_, size_t source_, size_t number_)=0
Move the given number of bytes at the given location to the new location Buffer should do this in the...
AMPS::Buffer::setPosition
virtual void setPosition(size_t position_)=0
Set the buffer postion to a location.
AMPS::Buffer::getUint64
virtual amps_uint64_t getUint64()=0
Get an unsigned 64-bit int value at the current buffer position and advance past it.
AMPS::Buffer::getInt64
virtual amps_int64_t getInt64()=0
Get a 64-bit int value at the current buffer position and advance past it.
AMPS::Buffer::getInt32
virtual amps_int32_t getInt32()=0
Get the 32-bit int value at the current buffer position and advance past it.