26 #ifndef _MEMORYSTOREBUFFER_H_ 27 #define _MEMORYSTOREBUFFER_H_ 32 #include <sys/types.h> 54 , _bufferLen(AMPS_MEMORYBUFFER_DEFAULT_LENGTH), _bufferPos(0)
64 return _buffer == NULL ? 0 : _bufferLen;
69 if (_buffer != NULL && newSize_ > _bufferLen)
71 char* _oldBuffer = _buffer;
72 _buffer =
new char[newSize_];
73 memcpy(_buffer, _oldBuffer, _bufferLen);
76 else if (_buffer == NULL)
78 _buffer =
new char[newSize_];
80 _bufferLen = newSize_;
90 while (position_ > _bufferLen)
94 _bufferPos = position_;
100 _buffer[_bufferPos++] = byte_;
105 return _buffer[_bufferPos++];
108 virtual void putLong(
long l_)
110 *((
long*)(_buffer + _bufferPos)) = l_;
111 _bufferPos +=
sizeof(long);
114 virtual long getLong()
116 _bufferPos +=
sizeof(long);
117 return *((
long*)(_buffer + _bufferPos -
sizeof(
long)));
120 virtual void putUnsignedLong(
unsigned long l_)
122 *((
unsigned long*)(_buffer + _bufferPos)) = l_;
123 _bufferPos +=
sizeof(
unsigned long);
126 virtual unsigned long getUnsignedLong()
128 _bufferPos +=
sizeof(
unsigned long);
129 return *((
unsigned long*)(_buffer + _bufferPos -
sizeof(
unsigned long)));
134 *((
size_t*)(_buffer + _bufferPos)) = s_;
135 _bufferPos +=
sizeof(size_t);
140 _bufferPos +=
sizeof(size_t);
141 return *((
size_t*)(_buffer + _bufferPos -
sizeof(
size_t)));
146 *((amps_int32_t*)(_buffer + _bufferPos)) = s_;
147 _bufferPos +=
sizeof(amps_int32_t);
152 _bufferPos +=
sizeof(amps_int32_t);
153 return *((amps_int32_t*)(_buffer + _bufferPos -
sizeof(amps_int32_t)));
158 *((amps_uint32_t*)(_buffer + _bufferPos)) = s_;
159 _bufferPos +=
sizeof(amps_uint32_t);
164 _bufferPos +=
sizeof(amps_uint32_t);
165 return *((amps_uint32_t*)(_buffer + _bufferPos -
sizeof(amps_uint32_t)));
170 *((amps_int64_t*)(_buffer + _bufferPos)) = s_;
171 _bufferPos +=
sizeof(amps_int64_t);
176 _bufferPos +=
sizeof(amps_int64_t);
177 return *((amps_int64_t*)(_buffer + _bufferPos -
sizeof(amps_int64_t)));
182 *((amps_uint64_t*)(_buffer + _bufferPos)) = s_;
183 _bufferPos +=
sizeof(amps_uint64_t);
188 _bufferPos +=
sizeof(amps_uint64_t);
189 return *((amps_uint64_t*)(_buffer + _bufferPos -
sizeof(amps_uint64_t)));
192 virtual void putBytes(
const char* data_,
size_t dataLength_)
194 memcpy(_buffer + _bufferPos, data_, dataLength_);
195 _bufferPos += dataLength_;
198 virtual void putBytes(
const Buffer::ByteArray& bytes_)
200 memcpy(_buffer + _bufferPos, bytes_._data, bytes_._len);
201 _bufferPos += bytes_._len;
204 virtual Buffer::ByteArray
getBytes(
size_t numBytes_)
206 Buffer::ByteArray retVal(_buffer + _bufferPos, numBytes_,
false);
207 _bufferPos += numBytes_;
214 memcpy(buffer_, _buffer + _bufferPos, numBytes_);
215 _bufferPos += numBytes_;
218 virtual void zero(
size_t offset_,
size_t length_)
220 memset(_buffer + offset_, 0, length_);
224 virtual void copyBytes(
size_t destination_,
size_t source_,
size_t number_)
227 memmove(_buffer + destination_, _buffer + source_, number_);
228 _bufferPos += number_;
232 enum CtorFlag { EMPTY };
246 #endif //_MEMORYSTOREBUFFER_H_ virtual void putUint32(amps_uint32_t s_)
Put an unsigned 32-bit int value into the buffer at the current position and advance past the end of ...
Definition: MemoryStoreBuffer.hpp:156
virtual char getByte()
Get the next byte from the buffer and advance.
Definition: MemoryStoreBuffer.hpp:103
virtual amps_uint32_t getUint32()
Get the unsigned 32-bit int value at the current buffer position and advance past it...
Definition: MemoryStoreBuffer.hpp:162
virtual void putByte(char byte_)
Put a byte into the buffer at the current position and advance.
Definition: MemoryStoreBuffer.hpp:98
virtual void copyBytes(char *buffer_, size_t numBytes_)
Copy the given number of bytes from this buffer to the given buffer.
Definition: MemoryStoreBuffer.hpp:212
virtual void putInt32(amps_int32_t s_)
Put a 32-bit int value into the buffer and advance past it.
Definition: MemoryStoreBuffer.hpp:144
virtual size_t getSize() const
Get the current size of the Buffer in bytes.
Definition: MemoryStoreBuffer.hpp:62
virtual amps_int64_t getInt64()
Get a 64-bit int value at the current buffer position and advance past it.
Definition: MemoryStoreBuffer.hpp:174
virtual amps_uint64_t getUint64()
Get an unsigned 64-bit int value at the current buffer position and advance past it.
Definition: MemoryStoreBuffer.hpp:186
A Buffer implementation that uses memory for storage.
Definition: MemoryStoreBuffer.hpp:50
virtual void setSize(size_t newSize_)
Set the size for the buffer.
Definition: MemoryStoreBuffer.hpp:67
Core type, function, and class declarations for the AMPS C++ client.
Provides AMPS::Buffer, an abstract base class used by the store implementations in the AMPS client...
virtual void copyBytes(size_t destination_, size_t source_, size_t number_)
Move the given number of bytes at the given location to the new location Buffer should do this in the...
Definition: MemoryStoreBuffer.hpp:224
virtual size_t getPosition() const
Get the current position in the buffer.
Definition: MemoryStoreBuffer.hpp:83
virtual size_t getSizet()
Get a size_t value at the current buffer position and advance past it.
Definition: MemoryStoreBuffer.hpp:138
virtual void zero(size_t offset_, size_t length_)
Set the given number of bytes in the buffer to zero starting at the given position.
Definition: MemoryStoreBuffer.hpp:218
virtual Buffer::ByteArray getBytes(size_t numBytes_)
Get the given number of bytes from the buffer.
Definition: MemoryStoreBuffer.hpp:204
virtual void setPosition(size_t position_)
Set the buffer postion to a location.
Definition: MemoryStoreBuffer.hpp:88
virtual void putBytes(const Buffer::ByteArray &bytes_)
Put the given bytes into the buffer at the current position and advance past them.
Definition: MemoryStoreBuffer.hpp:198
Abstract base class for implementing a buffer to be used by a StoreImpl for storage of publish messag...
Definition: Buffer.hpp:40
virtual void putSizet(size_t s_)
Put a size_t value into the buffer at the current position and advance past it.
Definition: MemoryStoreBuffer.hpp:132
virtual void putBytes(const char *data_, size_t dataLength_)
Put the given length of bytes in data into the buffer at the current position and advance past them...
Definition: MemoryStoreBuffer.hpp:192
virtual void putUint64(amps_uint64_t s_)
Put an amps_uint64_t value into the buffer at the current position and advance past it...
Definition: MemoryStoreBuffer.hpp:180
virtual amps_int32_t getInt32()
Get the 32-bit int value at the current buffer position and advance past it.
Definition: MemoryStoreBuffer.hpp:150
Definition: ampsplusplus.hpp:102
virtual void putInt64(amps_int64_t s_)
Put an amps_int64_t value into the buffer at the current position and advance past it...
Definition: MemoryStoreBuffer.hpp:168