bytebuffer Class Reference

Inherits output.

Inherited by stringbuffer, and wstringbuffer.

## Public Member Functions

| bytebuffer ()
| bytebuffer (size_t initialsize)
| bytebuffer (unsigned char *initialcontents, size_t initialsize)
| bytebuffer (const bytebuffer &v)
bytebuffer & | operator= (const bytebuffer &v)
virtual | ~bytebuffer ()
void | setPosition (size_t pos)
size_t | getPosition ()
ssize_t | write (const unsigned char *data, size_t size)
ssize_t | write (const char *string, size_t length)
ssize_t | write (const char *string)
ssize_t | write (const wchar_t *string, size_t length)
ssize_t | write (const wchar_t *string)
ssize_t | write (char character)
ssize_t | write (wchar_t character)
ssize_t | write (int16_t number)
ssize_t | write (int32_t number)
ssize_t | write (int64_t number)
ssize_t | write (unsigned char character)
ssize_t | write (uint16_t number)
ssize_t | write (uint32_t number)
ssize_t | write (uint64_t number)
ssize_t | write (float number)
ssize_t | write (double number)
ssize_t | writeFormatted (const char *format,...)
ssize_t | writeFormatted (const char *format, va_list *argp)
ssize_t | writeFormatted (const wchar_t *format,...)
ssize_t | writeFormatted (const wchar_t *format, va_list *argp)
bytebuffer * | append (const unsigned char *data, size_t size)
bytebuffer * | append (const char *string, size_t length)
bytebuffer * | append (const char *string)
bytebuffer * | append (const wchar_t *string, size_t length)
bytebuffer * | append (const wchar_t *string)
bytebuffer * | append (char character)
bytebuffer * | append (wchar_t character)
bytebuffer * | append (int16_t number)
bytebuffer * | append (int32_t number)
bytebuffer * | append (int64_t number)
bytebuffer * | append (unsigned char character)
bytebuffer * | append (uint16_t number)
bytebuffer * | append (uint32_t number)
bytebuffer * | append (uint64_t number)
bytebuffer * | append (float number)
bytebuffer * | append (double number)
bytebuffer * | appendFormatted (const char *format,...)
bytebuffer * | appendFormatted (const char *format, va_list *argp)
bytebuffer * | appendFormatted (const wchar_t *format,...)
bytebuffer * | appendFormatted (const wchar_t *format, va_list *argp)
virtual void | truncate (size_t pos)
virtual void | truncate ()
ssize_t | read (unsigned char *data, size_t size)
void | clear ()
void | clear (size_t initialsize)
void | clear (unsigned char *initialcontents, size_t initialsize)
const unsigned char * | getBuffer ()
size_t | getSize ()
size_t | getActualSize ()
size_t | getInitialSize ()
unsigned char * | detachBuffer ()
Public Member Functions inherited from output
virtual ssize_t | write (const unsigned char *string, size_t size, int32_t sec, int32_t usec)
virtual ssize_t | write (const char *string, int32_t sec, int32_t usec)
virtual ssize_t | write (const char *string, size_t length, int32_t sec, int32_t usec)
virtual ssize_t | write (char character, int32_t sec, int32_t usec)
virtual ssize_t | write (int16_t number, int32_t sec, int32_t usec)
virtual ssize_t | write (int32_t number, int32_t sec, int32_t usec)
virtual ssize_t | write (int64_t number, int32_t sec, int32_t usec)
virtual ssize_t | write (unsigned char character, int32_t sec, int32_t usec)
virtual ssize_t | write (uint16_t number, int32_t sec, int32_t usec)
virtual ssize_t | write (uint32_t number, int32_t sec, int32_t usec)
virtual ssize_t | write (uint64_t number, int32_t sec, int32_t usec)
virtual ssize_t | write (float number, int32_t sec, int32_t usec)
virtual ssize_t | write (double number, int32_t sec, int32_t usec)

## Detailed Description

The bytebuffer class can be used to store binary data of arbitrary length.

It is generally more efficient to reuse the same bytebuffer over and over than to allocate a new one for each operation.

## Constructor & Destructor Documentation

## bytebuffer() [1/4]

bytebuffer::bytebuffer | ( |  | ) |

Creates an instance of the bytebuffer class with default initial size and increment parameters.

## bytebuffer() [2/4]

bytebuffer::bytebuffer | ( | size_t | initialsize | ) |

Creates an instance of the bytebuffer class with the specified "initialsize".

## bytebuffer() [3/4]

bytebuffer::bytebuffer | ( | unsigned char * | initialcontents,
|  | size_t | initialsize
| ) |  |

Creates an instance of the bytebuffer class. The buffer "initialcontents" will be attached to the instance and used as the initial contents. This buffer should not be freed by the calling program.

## bytebuffer() [4/4]

bytebuffer::bytebuffer | ( | const bytebuffer & | v | ) |

Creates an instance of the bytebuffer class that is a copy of "v".

## ~bytebuffer()

virtual bytebuffer::~bytebuffer | ( |  | ) |

virtual

Deletes this instance of the bytebuffer class.

## Member Function Documentation

## append() [1/16]

bytebuffer* bytebuffer::append | ( | char | character | ) |

Appends "character" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

## append() [2/16]

bytebuffer* bytebuffer::append | ( | const char * | string | ) |

Appends "string" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

## append() [3/16]

bytebuffer* bytebuffer::append | ( | const char * | string,
|  | size_t | length
| ) |  |

Appends the first "length" characters of "string" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

## append() [4/16]

bytebuffer* bytebuffer::append | ( | const unsigned char * | data,
|  | size_t | size
| ) |  |

Appends the first "size" bytes of "data" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

## append() [5/16]

bytebuffer* bytebuffer::append | ( | const wchar_t * | string | ) |

Appends "string" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

## append() [6/16]

bytebuffer* bytebuffer::append | ( | const wchar_t * | string,
|  | size_t | length
| ) |  |

Appends the first "length" characters of "string" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

## append() [7/16]

bytebuffer* bytebuffer::append | ( | double | number | ) |

Appends "number" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

## append() [8/16]

bytebuffer* bytebuffer::append | ( | float | number | ) |

Appends "number" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

## append() [9/16]

bytebuffer* bytebuffer::append | ( | int16_t | number | ) |

Appends "number" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

## append() [10/16]

bytebuffer* bytebuffer::append | ( | int32_t | number | ) |

Appends "number" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

## append() [11/16]

bytebuffer* bytebuffer::append | ( | int64_t | number | ) |

Appends "number" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

## append() [12/16]

bytebuffer* bytebuffer::append | ( | uint16_t | number | ) |

Appends "number" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

## append() [13/16]

bytebuffer* bytebuffer::append | ( | uint32_t | number | ) |

Appends "number" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

## append() [14/16]

bytebuffer* bytebuffer::append | ( | uint64_t | number | ) |

Appends "number" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

## append() [15/16]

bytebuffer* bytebuffer::append | ( | unsigned char | character | ) |

Appends "character" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

## append() [16/16]

bytebuffer* bytebuffer::append | ( | wchar_t | character | ) |

Appends "character" to the bytebuffer, growing the internal buffer as necessary to accommodate the new data.

Returns a pointer to "this" to enable chaining such as: vb->append("numbers: ")->append(5)->append(5.5);

## appendFormatted() [1/4]

bytebuffer* bytebuffer::appendFormatted | ( | const char * | format,
|  | va_list * | argp
| ) |  |

Appends "argp" to the byte buffer using "format" which should comply with standard printf formatting rules.

Note that argp is a pointer to a va_list, not just a va_list.

## appendFormatted() [2/4]

bytebuffer* bytebuffer::appendFormatted | ( | const char * | format,
|  |  | ...
| ) |  |

Appends "..." to the byte buffer using "format" which should comply with standard printf formatting rules.

## appendFormatted() [3/4]

bytebuffer* bytebuffer::appendFormatted | ( | const wchar_t * | format,
|  | va_list * | argp
| ) |  |

Appends "argp" to the byte buffer using "format" which should comply with standard wprintf formatting rules.

Note that argp is a pointer to a va_list, not just a va_list.

## appendFormatted() [4/4]

bytebuffer* bytebuffer::appendFormatted | ( | const wchar_t * | format,
|  |  | ...
| ) |  |

Appends "..." to the byte buffer using "format" which should comply with standard wprintf formatting rules.

## clear() [1/3]

void bytebuffer::clear | ( |  | ) |

Empties the bytebuffer.

## clear() [2/3]

void bytebuffer::clear | ( | size_t | initialsize | ) |

Empties the bytebuffer and resets the specified "initialsize" parameter.

## clear() [3/3]

void bytebuffer::clear | ( | unsigned char * | initialcontents,
|  | size_t | initialsize
| ) |  |

Empties the bytebuffer and attaches the buffer "initialcontents" to the instance as the initial contents. This buffer should not be freed by the calling program. Also resets the specified "initialsize".

## detachBuffer()

unsigned char* bytebuffer::detachBuffer | ( |  | ) |

Returns a pointer to the buffer currently stored in the bytebuffer, then resets the bytebuffer such that it will no longer use that buffer.

The calling program must deallocate the buffer returned from this method.

## getActualSize()

size_t bytebuffer::getActualSize | ( |  | ) |

Returns the actual number of bytes of internal storage used by the bytebuffer, which may be larger than the value returned by getSize() since the buffer grows in extents.

## getBuffer()

const unsigned char* bytebuffer::getBuffer | ( |  | ) |

Returns the current data stored in the bytebuffer.

## getInitialSize()

size_t bytebuffer::getInitialSize | ( |  | ) |

Returns the number of bytes in the original initial exent.

## getPosition()

size_t bytebuffer::getPosition | ( |  | ) |

Returns the position in the buffer at which the next write will occur.

## getSize()

size_t bytebuffer::getSize | ( |  | ) |

Returns the number of bytes currently stored in the bytebuffer.

## operator=()

bytebuffer& bytebuffer::operator= | ( | const bytebuffer & | v | ) |

Makes this instance of the bytebuffer class identical to "v".

## read()

ssize_t bytebuffer::read | ( | unsigned char * | data,
|  | size_t | size
| ) |  |

Reads "size" bytes from the bytebuffer at the current position into "data". Also increments the current position by "size" bytes. Returns the number of bytes read.

## setPosition()

void bytebuffer::setPosition | ( | size_t | pos | ) |

Sets the position in the internal buffer at which the next read or write will occur to "pos". If the position is set beyond the end of the buffer, the buffer will grow but the data between the current end of the buffer and the new position will be undefined.

## truncate() [1/2]

virtual void bytebuffer::truncate | ( |  | ) |

virtual

Truncates the bytebuffer at the current position.

Reimplemented in wstringbuffer, and stringbuffer.

## truncate() [2/2]

virtual void bytebuffer::truncate | ( | size_t | pos | ) |

virtual

Truncates the bytebuffer at position "pos".

Reimplemented in wstringbuffer, and stringbuffer.

## write() [1/16]

ssize_t bytebuffer::write | ( | char | character | ) |

virtual

Writes "character" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in stringbuffer.

## write() [2/16]

ssize_t bytebuffer::write | ( | const char * | string | ) |

virtual

Writes "string" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in stringbuffer.

## write() [3/16]

ssize_t bytebuffer::write | ( | const char * | string,
|  | size_t | length
| ) |  |

virtual

Writes the first "length" characters of "string" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in stringbuffer.

## write() [4/16]

ssize_t bytebuffer::write | ( | const unsigned char * | data,
|  | size_t | size
| ) |  |

virtual

Writes the first "size" bytes of "data" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in stringbuffer.

## write() [5/16]

ssize_t bytebuffer::write | ( | const wchar_t * | string | ) |

Writes "string" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

## write() [6/16]

ssize_t bytebuffer::write | ( | const wchar_t * | string,
|  | size_t | length
| ) |  |

Writes the first "length" characters of "string" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

## write() [7/16]

ssize_t bytebuffer::write | ( | double | number | ) |

virtual

Writes "number" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in wstringbuffer, and stringbuffer.

## write() [8/16]

ssize_t bytebuffer::write | ( | float | number | ) |

virtual

Writes "number" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in wstringbuffer, and stringbuffer.

## write() [9/16]

ssize_t bytebuffer::write | ( | int16_t | number | ) |

virtual

Writes "number" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in wstringbuffer, and stringbuffer.

## write() [10/16]

ssize_t bytebuffer::write | ( | int32_t | number | ) |

virtual

Writes "number" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in wstringbuffer, and stringbuffer.

## write() [11/16]

ssize_t bytebuffer::write | ( | int64_t | number | ) |

virtual

Writes "number" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in wstringbuffer, and stringbuffer.

## write() [12/16]

ssize_t bytebuffer::write | ( | uint16_t | number | ) |

virtual

Writes "number" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in wstringbuffer, and stringbuffer.

## write() [13/16]

ssize_t bytebuffer::write | ( | uint32_t | number | ) |

virtual

Writes "number" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in wstringbuffer, and stringbuffer.

## write() [14/16]

ssize_t bytebuffer::write | ( | uint64_t | number | ) |

virtual

Writes "number" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in wstringbuffer, and stringbuffer.

## write() [15/16]

ssize_t bytebuffer::write | ( | unsigned char | character | ) |

virtual

Writes "character" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

Implements output.

Reimplemented in stringbuffer.

## write() [16/16]

ssize_t bytebuffer::write | ( | wchar_t | character | ) |

Writes "character" to the bytebuffer at the current position and increments the current position to the next byte after the data that was written. If necessary, the internal buffer will grow to accommodate the new data.

Returns the number of bytes written.

## writeFormatted() [1/4]

ssize_t bytebuffer::writeFormatted | ( | const char * | format,
|  | va_list * | argp
| ) |  |

Writes "argp" to the byte buffer using "format" which should comply with standard printf formatting rules.

Note that argp is a pointer to a va_list, not just a va_list.

Returns the number of bytes written.

## writeFormatted() [2/4]

ssize_t bytebuffer::writeFormatted | ( | const char * | format,
|  |  | ...
| ) |  |

Writes "..." to the byte buffer using "format" which should comply with standard printf formatting rules.

Returns the number of bytes written.

## writeFormatted() [3/4]

ssize_t bytebuffer::writeFormatted | ( | const wchar_t * | format,
|  | va_list * | argp
| ) |  |

Writes "argp" to the byte buffer using "format" which should comply with standard wprintf formatting rules.

Note that argp is a pointer to a va_list, not just a va_list.

Returns the number of bytes written.

## writeFormatted() [4/4]

ssize_t bytebuffer::writeFormatted | ( | const wchar_t * | format,
|  |  | ...
| ) |  |

Writes "..." to the byte buffer using "format" which should comply with standard wprintf formatting rules.

Returns the number of bytes written.