17#include <boost/shared_ptr.hpp>
91 : base_(static_cast<const uint8_t*>(data)), current_(base_),
97 return (
static_cast<size_t>(end_ - base_));
102 return (
static_cast<size_t>(current_ - base_));
113 if (base_ + position > end_) {
115 "InputBuffer::setPosition position is too large");
118 current_ = base_ + position;
126 if (current_ +
sizeof(uint8_t) > end_) {
128 "InputBuffer::peekUint8 read beyond end of buffer");
140 current_ +=
sizeof(uint8_t);
150 if (current_ +
sizeof(uint16_t) > end_) {
152 "InputBuffer::peekUint16 read beyond end of buffer");
156 ret = (
static_cast<uint16_t
>(current_[0])) << 8;
157 ret |= (
static_cast<uint16_t
>(current_[1]));
168 current_ +=
sizeof(uint16_t);
178 if (current_ +
sizeof(uint32_t) > end_) {
180 "InputBuffer::peekUint32 read beyond end of buffer");
184 ret = (
static_cast<uint32_t
>(current_[0])) << 24;
185 ret |= (
static_cast<uint32_t
>(current_[1])) << 16;
186 ret |= (
static_cast<uint32_t
>(current_[2])) << 8;
187 ret |= (
static_cast<uint32_t
>(current_[3]));
198 current_ +=
sizeof(uint32_t);
211 if (current_ + len > end_) {
213 "InputBuffer::peekData read beyond end of buffer");
216 static_cast<void>(std::memmove(data, current_, len));
241 if (current_ + len > end_) {
243 "InputBuffer::peekVector read beyond end of buffer");
266 const uint8_t* base_;
269 const uint8_t* current_;
350 buffer_.reserve(len);
358 size_t len = other.buffer_.capacity();
360 buffer_.reserve(len);
371 if (
this != &other) {
373 buffer_ = other.buffer_;
374 size_t len = other.buffer_.capacity();
376 buffer_.reserve(len);
385 return (buffer_.capacity());
396 if (!buffer_.empty()) {
397 return (&buffer_[0]);
405 return (
static_cast<const void*
>(
getData()));
410 return (buffer_.size());
421 if (position >= buffer_.size()) {
423 "OutputBuffer::[]: pos (" << position
424 <<
") >= size (" << buffer_.size() <<
")");
427 return (buffer_[position]);
446 buffer_.resize(buffer_.size() + len);
457 if (len > buffer_.size()) {
459 "OutputBuffer::trim length too large from output buffer");
462 buffer_.resize(buffer_.size() - len);
474 buffer_.push_back(data);
486 if (position +
sizeof(data) > buffer_.size()) {
488 "OutputBuffer::writeUint8At write at invalid position");
491 buffer_[position] = data;
499 buffer_.push_back(
static_cast<uint8_t
>((data & 0xff00U) >> 8));
500 buffer_.push_back(
static_cast<uint8_t
>(data & 0x00ffU));
515 if (position +
sizeof(data) > buffer_.size()) {
517 "OutputBuffer::writeUint16At write at invalid position");
520 buffer_[position] =
static_cast<uint8_t
>((data & 0xff00U) >> 8);
521 buffer_[position + 1] =
static_cast<uint8_t
>(data & 0x00ffU);
529 buffer_.push_back(
static_cast<uint8_t
>((data & 0xff000000) >> 24));
530 buffer_.push_back(
static_cast<uint8_t
>((data & 0x00ff0000) >> 16));
531 buffer_.push_back(
static_cast<uint8_t
>((data & 0x0000ff00) >> 8));
532 buffer_.push_back(
static_cast<uint8_t
>(data & 0x000000ff));
540 buffer_.push_back(
static_cast<uint8_t
>((data & 0xff00000000000000) >> 56));
541 buffer_.push_back(
static_cast<uint8_t
>((data & 0x00ff000000000000) >> 48));
542 buffer_.push_back(
static_cast<uint8_t
>((data & 0x0000ff0000000000) >> 40));
543 buffer_.push_back(
static_cast<uint8_t
>((data & 0x000000ff00000000) >> 32));
544 buffer_.push_back(
static_cast<uint8_t
>((data & 0x00000000ff000000) >> 24));
545 buffer_.push_back(
static_cast<uint8_t
>((data & 0x0000000000ff0000) >> 16));
546 buffer_.push_back(
static_cast<uint8_t
>((data & 0x000000000000ff00) >> 8));
547 buffer_.push_back(
static_cast<uint8_t
>(data & 0x00000000000000ff));
561 const uint8_t* ptr =
static_cast<const uint8_t*
>(data);
562 buffer_.insert(buffer_.end(), ptr, ptr + len);
567 std::vector<uint8_t> buffer_;
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
OutputBuffer & operator=(const OutputBuffer &other)
Assignment operator.
~OutputBuffer()=default
Destructor.
void writeUint64(uint64_t data)
Write an unsigned 64-bit integer in host byte order into the buffer in network byte order.
OutputBuffer(const OutputBuffer &other)
Copy constructor.
void writeUint8(uint8_t data)
Write an unsigned 8-bit integer into the buffer.
void writeUint16(uint16_t data)
Write an unsigned 16-bit integer in host byte order into the buffer in network byte order.
const void * getDataAsVoidPtr() const
Return data as a pointer to void.
void writeUint16At(uint16_t data, size_t position)
Write an unsigned 16-bit integer in host byte order at the specified position of the buffer in networ...
uint8_t operator[](size_t position) const
Return the value of the buffer at the specified position.
void writeData(const void *data, size_t len)
Copy an arbitrary length of data into the buffer.
void writeUint32(uint32_t data)
Write an unsigned 32-bit integer in host byte order into the buffer in network byte order.
void trim(size_t len)
Trim the specified length of data from the end of the buffer.
OutputBuffer(size_t len)
Constructor.
void skip(size_t len)
Insert a specified length of gap at the end of the buffer.
const uint8_t * getData() const
Return a pointer to the head of the data stored in the buffer.
size_t getLength() const
Return the length of data written in the buffer.
void clear()
Clear buffer content.
size_t getCapacity() const
Return the current capacity of the buffer.
void writeUint8At(uint8_t data, size_t position)
Write an unsigned 8-bit integer into the buffer.
const std::vector< uint8_t > & getVector() const
Return the buffer.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< InputBuffer > InputBufferPtr
Type of pointers to input buffer.
boost::shared_ptr< OutputBuffer > OutputBufferPtr
Type of pointers to output buffers.
Defines the logger used by the top-level component of kea-lfc.