Rudiments
Public Member Functions | List of all members
bytebuffer Class Reference

Inherited by stringbuffer.

Public Member Functions

 bytebuffer ()
 
 bytebuffer (size_t initialsize, size_t increment)
 
 bytebuffer (unsigned char *initialcontents, size_t initialsize, size_t increment)
 
 bytebuffer (const bytebuffer &v)
 
bytebufferoperator= (const bytebuffer &v)
 
virtual ~bytebuffer ()
 
void setPosition (size_t pos)
 
size_t getPosition ()
 
bytebufferwrite (const unsigned char *data, size_t size)
 
bytebufferwrite (const char *string)
 
bytebufferwrite (const char *string, size_t size)
 
bytebufferwrite (char character)
 
bytebufferwrite (int16_t number)
 
bytebufferwrite (int32_t number)
 
bytebufferwrite (int64_t number)
 
bytebufferwrite (unsigned char character)
 
bytebufferwrite (uint16_t number)
 
bytebufferwrite (uint32_t number)
 
bytebufferwrite (uint64_t number)
 
bytebufferwrite (float number)
 
bytebufferwrite (double number)
 
bytebufferwriteFormatted (const char *format,...)
 
bytebufferwriteFormatted (const char *format, va_list *argp)
 
bytebufferappend (const unsigned char *data, size_t size)
 
bytebufferappend (const char *string)
 
bytebufferappend (const char *string, size_t size)
 
bytebufferappend (char character)
 
bytebufferappend (int16_t number)
 
bytebufferappend (int32_t number)
 
bytebufferappend (int64_t number)
 
bytebufferappend (unsigned char character)
 
bytebufferappend (uint16_t number)
 
bytebufferappend (uint32_t number)
 
bytebufferappend (uint64_t number)
 
bytebufferappend (float number)
 
bytebufferappend (double number)
 
bytebufferappendFormatted (const char *format,...)
 
bytebufferappendFormatted (const char *format, va_list *argp)
 
virtual void truncate (size_t pos)
 
virtual void truncate ()
 
ssize_t read (unsigned char *data, size_t size)
 
void clear ()
 
const unsigned char * getBuffer ()
 
size_t getSize ()
 
size_t getEnd ()
 
size_t getActualSize ()
 
unsigned char * detachBuffer ()
 

Detailed Description

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

Internally, the class stores this data in a series of extents which are coalesced when getBuffer() or detachBuffer() are called. The size of the initial and incremental extents may be defined in the constructor.

When cleared, all extents except for the initial extent are freed.

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,
size_t  increment 
)

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

◆ bytebuffer() [3/4]

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

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. The initial size and increment may be specified respectively by the "initialsize" and "increment" parameters.

◆ 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/13]

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() [2/13]

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/13]

bytebuffer* bytebuffer::append ( const char *  string,
size_t  size 
)

Appends the first "size" bytes 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/13]

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() [5/13]

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() [6/13]

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() [7/13]

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() [8/13]

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() [9/13]

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() [10/13]

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() [11/13]

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() [12/13]

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() [13/13]

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);

◆ appendFormatted() [1/2]

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

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

◆ appendFormatted() [2/2]

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.

◆ clear()

void bytebuffer::clear ( )

Empties the bytebuffer.

◆ 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 size of the buffer which may be larger than the value returned by getSize() since the buffer grows in chunks.

◆ getBuffer()

const unsigned char* bytebuffer::getBuffer ( )

Returns the current data stored in the bytebuffer.

◆ getEnd()

size_t bytebuffer::getEnd ( )

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

◆ 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 amount of data 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.

◆ 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 ( size_t  pos)
virtual

Truncates the bytebuffer at position "pos".

Reimplemented in stringbuffer.

◆ truncate() [2/2]

virtual void bytebuffer::truncate ( )
virtual

Truncates the bytebuffer at the current position.

Reimplemented in stringbuffer.

◆ write() [1/13]

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

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 a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

◆ write() [2/13]

bytebuffer* bytebuffer::write ( const char *  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 a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

◆ write() [3/13]

bytebuffer* bytebuffer::write ( const char *  string,
size_t  size 
)

Writes the first "size" bytes 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 a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

◆ write() [4/13]

bytebuffer* bytebuffer::write ( char  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 a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

◆ write() [5/13]

bytebuffer* bytebuffer::write ( int16_t  number)

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 a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

◆ write() [6/13]

bytebuffer* bytebuffer::write ( int32_t  number)

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 a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

◆ write() [7/13]

bytebuffer* bytebuffer::write ( int64_t  number)

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 a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

◆ write() [8/13]

bytebuffer* bytebuffer::write ( unsigned char  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 a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

◆ write() [9/13]

bytebuffer* bytebuffer::write ( uint16_t  number)

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 a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

◆ write() [10/13]

bytebuffer* bytebuffer::write ( uint32_t  number)

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 a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

◆ write() [11/13]

bytebuffer* bytebuffer::write ( uint64_t  number)

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 a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

◆ write() [12/13]

bytebuffer* bytebuffer::write ( float  number)

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 a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

◆ write() [13/13]

bytebuffer* bytebuffer::write ( double  number)

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 a pointer to "this" to enable chaining such as: vb->write("numbers: ")->write(5)->write(5.5);

◆ writeFormatted() [1/2]

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

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

◆ writeFormatted() [2/2]

bytebuffer* 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.