#include <coherence/io/OctetArrayWriteBuffer.hpp>
Inherits AbstractWriteBuffer.
Inherited by BinaryWriteBuffer.
It is designed to support both fixed length buffers and resizable buffers.
This implementation is explicitly not thread-safe.
Public Types | |||||||||||||||||||
typedef spec::Handle | Handle | ||||||||||||||||||
OctetArrayWriteBuffer Handle definition. | |||||||||||||||||||
typedef spec::View | View | ||||||||||||||||||
OctetArrayWriteBuffer View definition. | |||||||||||||||||||
typedef spec::Holder | Holder | ||||||||||||||||||
OctetArrayWriteBuffer Holder definition. | |||||||||||||||||||
typedef this_spec::Handle | Handle | ||||||||||||||||||
AbstractWriteBuffer Handle definition. | |||||||||||||||||||
typedef this_spec::View | View | ||||||||||||||||||
AbstractWriteBuffer View definition. | |||||||||||||||||||
typedef this_spec::Holder | Holder | ||||||||||||||||||
AbstractWriteBuffer Holder definition. | |||||||||||||||||||
Public Member Functions | |||||||||||||||||||
virtual size32_t | length () const | ||||||||||||||||||
Determine the length of the data that is in the buffer. This is the actual number of octets of data that have been written to the buffer, not the capacity of the buffer.
| |||||||||||||||||||
virtual size32_t | getCapacity () const | ||||||||||||||||||
Determine the number of octets that the buffer can hold without resizing itself.
In other words, a WriteBuffer has Note that if the maximum size returned by getMaximumCapacity() is greater than the current size returned by this method, then the WriteBuffer will automatically resize itself to allocate more space when the amount of data written to it passes the current size.
| |||||||||||||||||||
virtual size32_t | getMaximumCapacity () const | ||||||||||||||||||
Determine the maximum number of octets that the buffer can hold. If the maximum size is greater than the current size, then the buffer is expected to resize itself as necessary up to the maximum size in order to contain the data given to it.
| |||||||||||||||||||
virtual void | write (size32_t ofDest, octet_t b) | ||||||||||||||||||
Store the specified octet at the specified offset within the buffer. For purposes of side-effects and potential exceptions, this method is functionally equivalent to the following code:
| |||||||||||||||||||
virtual void | write (size32_t ofDest, Array< octet_t >::View vabSrc, size32_t ofSrc, size32_t cbSrc) | ||||||||||||||||||
Store the specified number of octets from the specified location within the passed octet array at the specified offset within this buffer.
As a result of this method, the buffer length as reported by the
As a result of this method, the buffer capacity as reported by the
| |||||||||||||||||||
virtual void | write (size32_t ofDest, ReadBuffer::View vBufSrc, size32_t ofSrc, size32_t cbSrc) | ||||||||||||||||||
Store the specified portion of the contents of the specified ReadBuffer at the specified offset within this buffer. For purposes of side-effects and potential exceptions, this method is functionally equivalent to the following code:
| |||||||||||||||||||
virtual void | retain (size32_t of, size32_t cb) | ||||||||||||||||||
Starting with the octet at offset of , retain cb octets in this WriteBuffer, such that the octet at offset of is shifted to offset 0, the octet at offset of + 1 is shifted to offset 1, and so on up to the octet at offset of + cb - 1 , which is shifted to offset cb - 1 .
After this method, the length of the buffer as indicated by the length() method will be equal to
Legal values for the offset of the first octet to retain
If The effect on the capacity of the buffer is implementation- specific; some implementations are expected to retain the same capacity while others are expected to shrink accordingly.
| |||||||||||||||||||
virtual ReadBuffer::View | getUnsafeReadBuffer () const | ||||||||||||||||||
Get a ReadBuffer object to read data from this buffer. This method is not guaranteed to return a snapshot of this buffer's data, nor is it guaranteed to return a live view of this buffer, which means that subsequent changes to this WriteBuffer may or may not affect the contents and / or the length of the returned ReadBuffer. To get a snapshot, use the getReadBuffer() method.
| |||||||||||||||||||
Protected Member Functions | |||||||||||||||||||
OctetArrayWriteBuffer (Array< octet_t >::Handle hab) | |||||||||||||||||||
Construct an OctetArrayWriteBuffer on an octet array. | |||||||||||||||||||
OctetArrayWriteBuffer (size32_t cbCap, size32_t cbMax=(std::numeric_limits< size32_t >::max)()) | |||||||||||||||||||
Construct an OctetArrayWriteBuffer with a certain initial capacity and a certain maximum capacity. | |||||||||||||||||||
OctetArrayWriteBuffer (const OctetArrayWriteBuffer &that) | |||||||||||||||||||
Copy constructor. | |||||||||||||||||||
virtual BufferOutput::Handle | instantiateBufferOutput () | ||||||||||||||||||
Factory method: Instantiate a BufferOutput object to write data to the WriteBuffer.
| |||||||||||||||||||
virtual void | checkBounds (size32_t of, size32_t cb) | ||||||||||||||||||
Validate the ranges for the passed bounds and make sure that the underlying array is big enough to handle them. | |||||||||||||||||||
virtual void | grow (size32_t cbCap) | ||||||||||||||||||
Grow the underlying octet array to at least the specified size. | |||||||||||||||||||
virtual void | updateLength (size32_t cb) | ||||||||||||||||||
Update the length if the passed length is greater than the current buffer length. | |||||||||||||||||||
virtual void | onEscape (bool fEscaped) const | ||||||||||||||||||
Event called when the guarding Object's escape state changes. As with all event methods any derived implementation should include a call to the super class's implementation. Ultimately delegation must reach Object::onEscape() which will perform the actual act of preparing the object for multi/single-threaded access. Throughout the call it is guaranteed that the object remains visible to only a single thread, and as such it is not allowable to perform an action from within this method which would attempt to escape this object.
| |||||||||||||||||||
Protected Attributes | |||||||||||||||||||
MemberHandle< Array < octet_t > > | m_hab | ||||||||||||||||||
The octet array that holds the binary data. | |||||||||||||||||||
octet_t * | m_pab | ||||||||||||||||||
Raw pointer to byte[] within m_hab, or NULL if this object is escaped which would make its use impossible to prove as safe. | |||||||||||||||||||
size32_t | m_cbab | ||||||||||||||||||
The cached size of m_hab. | |||||||||||||||||||
size32_t | m_cb | ||||||||||||||||||
Number of octets in the octet array that have been written by this WriteBuffer. | |||||||||||||||||||
size32_t | m_cbMax | ||||||||||||||||||
Number of octets that the octet array can be grown to. | |||||||||||||||||||
MemberHandle < ReadBuffer > | m_hBufUnsafe | ||||||||||||||||||
Cached ReadBuffer to quickly provide an answer to getUnsafeReadBuffer(). | |||||||||||||||||||
Classes | |||||||||||||||||||
class | OctetArrayBufferOutput | ||||||||||||||||||
OctetArrayBufferOutput is an implementation of BufferOutput optimized for writing to the buffer's underlying octet array. More... |
OctetArrayWriteBuffer | ( | Array< octet_t >::Handle | hab | ) | [protected] |
Construct an OctetArrayWriteBuffer on an octet array.
hab | an octet array |
NullPointerException | if hab is NULL |
OctetArrayWriteBuffer | ( | size32_t | cbCap, | |
size32_t | cbMax = (std::numeric_limits< size32_t >::max)() | |||
) | [protected] |
Construct an OctetArrayWriteBuffer with a certain initial capacity and a certain maximum capacity.
cbCap | initial capacity | |
cbMax | maximum capacity |
IllegalArgumentException | if cbCap is greater than cbMax |
virtual void checkBounds | ( | size32_t | of, | |
size32_t | cb | |||
) | [protected, virtual] |
Validate the ranges for the passed bounds and make sure that the underlying array is big enough to handle them.
of | the offset that data is about to be written to | |
cb | the length of the data that is about to be written |
Reimplemented in BinaryWriteBuffer.
virtual void grow | ( | size32_t | cbCap | ) | [protected, virtual] |
Grow the underlying octet array to at least the specified size.
cbCap | the required or requested capacity |
virtual void updateLength | ( | size32_t | cb | ) | [protected, virtual] |
Update the length if the passed length is greater than the current buffer length.
cb | the count of the last octet written (or the index of the next octet to write) |
size32_t m_cb [protected] |
Number of octets in the octet array that have been written by this WriteBuffer.
This is the length.
size32_t m_cbMax [protected] |
Number of octets that the octet array can be grown to.
This is the maximum capacity.