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 memcpy(_buffer + _bufferPos, &l_,
sizeof(l_));
111 _bufferPos +=
sizeof(long);
114 virtual long getLong()
117 memcpy(&l, _buffer + _bufferPos,
sizeof(l));
118 _bufferPos +=
sizeof(long);
122 virtual void putUnsignedLong(
unsigned long l_)
124 memcpy(_buffer + _bufferPos, &l_,
sizeof(l_));
125 _bufferPos +=
sizeof(
unsigned long);
128 virtual unsigned long getUnsignedLong()
131 memcpy(&l, _buffer + _bufferPos,
sizeof(l));
132 _bufferPos +=
sizeof(
unsigned long);
138 memcpy(_buffer + _bufferPos, &s_,
sizeof(s_));
139 _bufferPos +=
sizeof(size_t);
145 memcpy(&l, _buffer + _bufferPos,
sizeof(l));
146 _bufferPos +=
sizeof(size_t);
152 memcpy(_buffer + _bufferPos, &s_,
sizeof(s_));
153 _bufferPos +=
sizeof(amps_int32_t);
159 memcpy(&l, _buffer + _bufferPos,
sizeof(l));
160 _bufferPos +=
sizeof(amps_int32_t);
166 memcpy(_buffer + _bufferPos, &s_,
sizeof(s_));
167 _bufferPos +=
sizeof(amps_uint32_t);
173 memcpy(&l, _buffer + _bufferPos,
sizeof(l));
174 _bufferPos +=
sizeof(amps_uint32_t);
180 memcpy(_buffer + _bufferPos, &s_,
sizeof(s_));
181 _bufferPos +=
sizeof(amps_int64_t);
187 memcpy(&l, _buffer + _bufferPos,
sizeof(l));
188 _bufferPos +=
sizeof(amps_int64_t);
194 memcpy(_buffer + _bufferPos, &s_,
sizeof(s_));
195 _bufferPos +=
sizeof(amps_uint64_t);
201 memcpy(&l, _buffer + _bufferPos,
sizeof(l));
202 _bufferPos +=
sizeof(amps_uint64_t);
206 virtual void putBytes(
const char* data_,
size_t dataLength_)
208 memcpy(_buffer + _bufferPos, data_, dataLength_);
209 _bufferPos += dataLength_;
212 virtual void putBytes(
const Buffer::ByteArray& bytes_)
214 memcpy(_buffer + _bufferPos, bytes_._data, bytes_._len);
215 _bufferPos += bytes_._len;
218 virtual Buffer::ByteArray
getBytes(
size_t numBytes_)
220 Buffer::ByteArray retVal(_buffer + _bufferPos, numBytes_,
false);
221 _bufferPos += numBytes_;
228 memcpy(buffer_, _buffer + _bufferPos, numBytes_);
229 _bufferPos += numBytes_;
232 virtual void zero(
size_t offset_,
size_t length_)
234 memset(_buffer + offset_, 0, length_);
238 virtual void copyBytes(
size_t destination_,
size_t source_,
size_t number_)
241 memmove(_buffer + destination_, _buffer + source_, number_);
242 _bufferPos += number_;
246 enum CtorFlag { EMPTY };
247 MemoryStoreBuffer(CtorFlag)
Provides AMPS::Buffer, an abstract base class used by the store implementations in the AMPS client.
Core type, function, and class declarations for the AMPS C++ client.
Abstract base class for implementing a buffer to be used by a StoreImpl for storage of publish messag...
Definition: Buffer.hpp:41
A Buffer implementation that uses memory for storage.
Definition: MemoryStoreBuffer.hpp:51
virtual amps_uint64_t getUint64()
Get an unsigned 64-bit int value at the current buffer position and advance past it.
Definition: MemoryStoreBuffer.hpp:198
virtual amps_int32_t getInt32()
Get the 32-bit int value at the current buffer position and advance past it.
Definition: MemoryStoreBuffer.hpp:156
virtual char getByte()
Get the next byte from the buffer and advance.
Definition: MemoryStoreBuffer.hpp:103
virtual void putInt32(amps_int32_t s_)
Put a 32-bit int value into the buffer and advance past it.
Definition: MemoryStoreBuffer.hpp:150
virtual size_t getPosition() const
Get the current position in the buffer.
Definition: MemoryStoreBuffer.hpp:83
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:136
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:192
virtual void setPosition(size_t position_)
Set the buffer postion to a location.
Definition: MemoryStoreBuffer.hpp:88
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:232
virtual amps_uint32_t getUint32()
Get the unsigned 32-bit int value at the current buffer position and advance past it.
Definition: MemoryStoreBuffer.hpp:170
virtual amps_int64_t getInt64()
Get a 64-bit int value at the current buffer position and advance past it.
Definition: MemoryStoreBuffer.hpp:184
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:178
virtual Buffer::ByteArray getBytes(size_t numBytes_)
Get the given number of bytes from the buffer.
Definition: MemoryStoreBuffer.hpp:218
virtual size_t getSizet()
Get a size_t value at the current buffer position and advance past it.
Definition: MemoryStoreBuffer.hpp:142
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:212
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:238
virtual size_t getSize() const
Get the current size of the Buffer in bytes.
Definition: MemoryStoreBuffer.hpp:62
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:206
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:164
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:226
virtual void setSize(size_t newSize_)
Set the size for the buffer.
Definition: MemoryStoreBuffer.hpp:67