A way to store and pass binary buffers, for example compiled bytecode. More...
#include <binarybuffer.h>
Public Types | |
typedef Int8 | Byte |
The type of data this buffer can hold, it is intended to be some type one byte in length, but doesn't have to be. | |
Public Member Functions | |
BinaryBuffer () | |
Default constructor, set everything to zero. Doesn't allocate anything. | |
BinaryBuffer (const BinaryBuffer &Other) | |
Copy constructor. More... | |
BinaryBuffer (const Whole PredeterminedSize) | |
Terse constructor, set a custom size and allocates space (filled with gibberish). More... | |
BinaryBuffer (Byte *BinaryPointer, const Whole PredeterminedSize) | |
Verbose constructor, set everything custom on creation. More... | |
BinaryBuffer (const String &DataString, const Boole IsBase64=true) | |
Base64 decoding Constructor. More... | |
~BinaryBuffer () | |
Virtual deconstructor calls DeleteBuffer() to clean up whatever has been inserted here. More... | |
void | Concatenate (const Byte *OtherBuffer, const Whole ByteSize) |
Append another group of arbitrary data onto this one. More... | |
void | Concatenate (const BinaryBuffer BufferFromAnotherMother) |
Concatenate another buffer onto this one. More... | |
void | CreateBuffer () |
This will create a buffer with size matching the this->Size and point this->Binary to that Buffer. More... | |
void | CreateFromBase64 (const String &EncodedBinaryData) |
This calls deallocates any space, allocates fresh space of the size requestedthen the Decodes the passed and repopulates the Buffer. More... | |
void | DeleteBuffer (const Whole NewSize=0) |
Deletes whatever Binary points at and assigns Size to 0. More... | |
Whole | GetSize () const |
Even though this class is intended to have its internals modified directly in some cases, In normal cases accessor are nice to have. More... | |
BinaryBuffer & | operator+= (const BinaryBuffer &RH) |
Addition Assignment Operator. More... | |
BinaryBuffer & | operator= (const BinaryBuffer &RH) |
Assignment Operator. More... | |
Byte & | operator[] (const Whole Index) |
Access a part of the buffer. More... | |
String | ToBase64String () |
Get the binary buffer as a base64 string. More... | |
String | ToString () |
Get the contents of this crudely converted to a c style string then stuff it in a string. More... | |
Public Attributes | |
Byte * | Binary |
A pointer to the actual binary data. | |
Whole | Size |
How many bytes is Binary in size. This is set to 0 if Binary is invalid and should be a null pointer. | |
A way to store and pass binary buffers, for example compiled bytecode.
Originally intended for use with ScriptCompilable as a basic way to store and pass bytecode around. This deletes the passed binary on destruction. To prevent this behavior set the Binary pointer to null.
This is designed to be fairly minimalistic but passing by value causes the buffer to be copied.
Where possible this class performs no speculative allocation unless explicitly requested to. In other words this should have allocated exactly as many bytes are indicated by the member Size, no more and no less. This will tend to not allocate memory unless an operation on it is specified that it does so.
Whenever this needs to allocated memory it will use the Size member for determining the amount to allocate. If that is 0 an InvalidStateException exception is thrown. Bounds checking, if performed, only occurs when MEZZ_DEBUG is enabled.
Definition at line 68 of file binarybuffer.h.
Mezzanine::BinaryTools::BinaryBuffer::BinaryBuffer | ( | const BinaryBuffer & | Other | ) |
Copy constructor.
Other | The buffer to be copied. |
Allocates identical amount of memory as other buffer then copies the other buffer into the allocated space. Each BinaryBuffer retains ownership of their respective buffers.
Definition at line 165 of file binarybuffer.cpp.
|
explicit |
Terse constructor, set a custom size and allocates space (filled with gibberish).
PredeterminedSize | The size to set on creation. |
Definition at line 176 of file binarybuffer.cpp.
Mezzanine::BinaryTools::BinaryBuffer::BinaryBuffer | ( | Byte * | BinaryPointer, |
const Whole | PredeterminedSize | ||
) |
Verbose constructor, set everything custom on creation.
If passed a pointer this assumes ownship of that pointer, otherwise this allocates the amount of space requested.
BinaryPointer | A pointer to the first byte in memory, if this is null the buffer is created. Ownership of this Pointer will be assumed. |
PredeterminedSize | The size to set on creation. |
Definition at line 181 of file binarybuffer.cpp.
|
explicit |
Base64 decoding Constructor.
Performs exactly one allocation of the amount required to store the decoded base64, Then starts filling it. If there is an error with the data as it is beign process the rest of the Buffer will be filled with gibberish, and everything before the error will be properly decoded.
DataString | A Base64 string to be decode and used as a binary buffer, or a string to be used a buffer if IsBase64 is false. |
IsBase64 | Is the String passed Base64 encoded. |
Definition at line 186 of file binarybuffer.cpp.
Mezzanine::BinaryTools::BinaryBuffer::~BinaryBuffer | ( | ) |
Virtual deconstructor calls DeleteBuffer() to clean up whatever has been inserted here.
If you do not want the Buffer pointed to by the pointer Binary assign Binary to 0 and this deconstructor will delete with erase nothing.
Definition at line 198 of file binarybuffer.cpp.
void Mezzanine::BinaryTools::BinaryBuffer::Concatenate | ( | const Byte * | OtherBuffer, |
const Whole | ByteSize | ||
) |
Append another group of arbitrary data onto this one.
Allocates space equal to the size of both buffers, Copies this Buffers data into it, then copies the other buffers data, then deallocates any space this buffer may have had allocated preivously.
OtherBuffer | A pointer to a region of memory to be copied. |
ByteSize | How big in bytes is the Buffer. |
Definition at line 238 of file binarybuffer.cpp.
void Mezzanine::BinaryTools::BinaryBuffer::Concatenate | ( | const BinaryBuffer | BufferFromAnotherMother | ) |
Concatenate another buffer onto this one.
This calls Concatenate(const Byte*, Whole)
BufferFromAnotherMother | A buffer to copy and append onto this one. |
Definition at line 250 of file binarybuffer.cpp.
void Mezzanine::BinaryTools::BinaryBuffer::CreateBuffer | ( | ) |
This will create a buffer with size matching the this->Size and point this->Binary to that Buffer.
Definition at line 204 of file binarybuffer.cpp.
void Mezzanine::BinaryTools::BinaryBuffer::CreateFromBase64 | ( | const String & | EncodedBinaryData | ) |
This calls deallocates any space, allocates fresh space of the size requestedthen the Decodes the passed and repopulates the Buffer.
EncodedBinaryData | The Base64 string containing binary data. |
Definition at line 221 of file binarybuffer.cpp.
void Mezzanine::BinaryTools::BinaryBuffer::DeleteBuffer | ( | const Whole | NewSize = 0 | ) |
Deletes whatever Binary points at and assigns Size to 0.
NewSize | If you don't want to just clear the buffer, but rather want to set size to a value and set a new size, you can do that with this. |
Definition at line 213 of file binarybuffer.cpp.
Whole Mezzanine::BinaryTools::BinaryBuffer::GetSize | ( | ) | const |
Even though this class is intended to have its internals modified directly in some cases, In normal cases accessor are nice to have.
Definition at line 261 of file binarybuffer.cpp.
BinaryBuffer & Mezzanine::BinaryTools::BinaryBuffer::operator+= | ( | const BinaryBuffer & | RH | ) |
Addition Assignment Operator.
An easier way to call Concatenate(const Byte*, const Whole)
RH | The other Buffer to copy/append. |
Definition at line 281 of file binarybuffer.cpp.
BinaryBuffer & Mezzanine::BinaryTools::BinaryBuffer::operator= | ( | const BinaryBuffer & | RH | ) |
Assignment Operator.
This deletes the buffer if it is not null, and allocates a fresh one of the size in RH, then copies it.
RH | The item on the right hand side. |
Definition at line 267 of file binarybuffer.cpp.
BinaryBuffer::Byte & Mezzanine::BinaryTools::BinaryBuffer::operator[] | ( | const Whole | Index | ) |
Access a part of the buffer.
Index | How from from the 0 aligned beginning of the buffer would you like to access. |
Definition at line 288 of file binarybuffer.cpp.
String Mezzanine::BinaryTools::BinaryBuffer::ToBase64String | ( | ) |
Get the binary buffer as a base64 string.
Definition at line 230 of file binarybuffer.cpp.
String Mezzanine::BinaryTools::BinaryBuffer::ToString | ( | ) |
Get the contents of this crudely converted to a c style string then stuff it in a string.
Definition at line 253 of file binarybuffer.cpp.