#include <buffer.h>
Public Member Functions | |
Buffer () | |
Create a new Buffer with the default size. | |
Buffer (size_t nbytes) | |
Create a new Buffer with a size other than the default. | |
Buffer (const std::string &str) | |
Create a new Buffer with a hex string. This is primary used only for testing to create binary data from an easy to read and edit format. | |
~Buffer () | |
Delete the memory allocated for this Buffer. | |
int | corrupt () |
Corrupt a buffer with random errors. This is used only for testing to make sure we can cleanly handle corruption of the packets. | |
int | corrupt (int factor) |
Buffer & | hex2mem (const std::string &str) |
Encode a Buffer from a hex string. | |
std::string | hexify () |
Output a debug version of the Buffer's data. This just calls the gnash::Logfile::hexify(), but is more convienient as we don't have to extract the pointer and the byte count to hexify() a Buffer. | |
std::string | hexify (bool ascii) |
std::string | hexify (Buffer &buf, bool ascii) |
void | clear () |
Clear the contents of the buffer by setting all the bytes to zeros. | |
bool | empty () |
Test to see if the buffer has any data. | |
Buffer & | resize () |
Resize the buffer that holds the data. The new size of the current data is based on the current amount of data within the allocated memory. This is used to make a Buffer the same size as the existing data, and to truncate the unsed portion of the Buffer when copying to the new memory location. | |
Buffer & | resize (size_t nbytes) |
Resize the buffer that holds the data. If the size is larger than the existing data, the data is copied into the new region. If the size is smaller than the existing data, the remaining data is truncated when copying to the new memory location. | |
Buffer & | copy (boost::uint8_t *data, size_t nbytes) |
Copy data into the buffer. This overwrites all data, and resets the seek ptr. | |
Buffer & | operator= (Buffer &buf) |
Copy a Buffer class into the buffer. This overwrites all data, and resets the seek ptr. | |
Buffer & | operator= (boost::shared_ptr< Buffer > &buf) |
Copy a Buffer class into the buffer. This overwrites all data, and resets the seek ptr. | |
Buffer & | operator= (const std::string &str) |
Copy a string into the buffer. This overwrites all data, and resets the seek ptr. | |
Buffer & | operator= (const char *str) |
Buffer & | operator= (double num) |
Copy a double into the buffer. This overwrites all data, and resets the seek ptr. | |
Buffer & | operator= (boost::uint16_t length) |
Copy a short into the buffer. This overwrites all data, and resets the seek ptr. | |
Buffer & | operator= (boost::uint8_t byte) |
Copy a byte into the buffer. This overwrites all data, and resets the seek ptr. | |
Buffer & | operator= (boost::uint8_t *byte) |
Copy a byte into the buffer. This overwrites all data, and resets the seek ptr. | |
Buffer & | operator= (cygnal::Element::amf0_type_e type) |
Copy a AMF0 type into the buffer. This overwrites all data, and resets the seek ptr. | |
Buffer & | operator= (bool flag) |
Buffer & | append (boost::uint8_t *data, size_t nbytes) |
Append data to existing data in the buffer. | |
Buffer & | operator+= (Buffer &buf) |
Append a Buffer class to existing data in the buffer. | |
Buffer & | operator+= (boost::shared_ptr< Buffer > &buf) |
Append a Buffer class to existing data in the buffer. | |
Buffer & | operator+= (const std::string &str) |
Append a string to existing data in the buffer. | |
Buffer & | operator+= (const char *str) |
Append a string to existing data in the buffer. | |
Buffer & | operator+= (double num) |
Append a double to existing data in the buffer. | |
Buffer & | operator+= (boost::uint32_t length) |
Append an integer to existing data in the buffer. | |
Buffer & | operator+= (boost::uint16_t length) |
Append a short to existing data in the buffer. | |
Buffer & | operator+= (boost::uint8_t byte) |
Append a byte to existing data in the buffer. | |
Buffer & | operator+= (char byte) |
Append a byte to existing data in the buffer. | |
Buffer & | operator+= (cygnal::Element::amf0_type_e type) |
Append an AMF0 type to existing data in the buffer. | |
Buffer & | operator+= (bool) |
Append a boolean to existing data in the buffer. | |
boost::uint8_t * | remove (boost::uint8_t c) |
Drop a byte without resizing. This will remove the byte from the Buffer, and then move the remaining data to be in the correct location. This resets the seek pointer. | |
boost::uint8_t * | remove (int index) |
Drop a byte without resizing. This will remove the byte from the Buffer, and then move the remaining data to be in the correct location. This resets the seek pointer. | |
boost::uint8_t * | remove (int start, int range) |
Drop bytes without resizing. This will remove the bytes from the Buffer, and then move the remaining data to be in the correct location. This resets the seek pointer. | |
boost::uint8_t * | begin () |
Return the base address of the Buffer. | |
boost::uint8_t * | reference () |
const boost::uint8_t * | reference () const |
boost::uint8_t * | end () |
Return the last address of the Buffer Which is the base address plus the total size of the Buffer. | |
size_t | size () |
Get the size of the Buffer. | |
void | setSize (size_t nbytes) |
Set the size of the Buffer. Note that this does not resize the Buffer, it merely is a convienient way to set the size field of the Buffer class, and should only be used by low level internal code and testing. | |
void | setPointer (boost::uint8_t *ptr) |
Set the real pointer to a block of Memory. | |
bool | operator== (Buffer &buf) |
Test equivalance against another Buffer. This compares all the data on the current Buffer with the supplied one, so it can be a performance hit. This is primarily only used for testing purposes. | |
boost::uint8_t | operator[] (int index) |
Get the byte at a specified location. | |
boost::uint8_t * | at (int index) |
Get the byte at a specified location. | |
size_t | spaceLeft () |
How much room is left in the buffer past the seek pointer. This is primarily used to see if the buffer is fully populated with data before appending more. | |
size_t | allocated () |
How much room has been allocated before the seek pointer. This is primarily used to see if the buffer is fully populated with data before appending more. | |
void | setSeekPointer (boost::uint8_t *ptr) |
Set the seek pointer. | |
void | setSeekPointer (off_t offset) |
void | dump () const |
Dump the internal data of this class in a human readable form. This should only be used for debugging purposes. | |
void | dump (std::ostream &os) const |
Dump the internal data of this class in a human readable form. This should only be used for debugging purposes. | |
Protected Attributes | |
boost::uint8_t * | _seekptr |
This is a pointer to the address in the Buffer to write data to then next time some is appended. | |
boost::scoped_array < boost::uint8_t > | _data |
This is the container of the actual data in this Buffer. | |
size_t | _nbytes |
This is the total allocated size of the Buffer. |
This class is used to hold all data for libamf classes. It is a simplified form of std::vector, but with more knowledge of data types when copying or appending data to make higher level code easier to read.
cygnal::Buffer::Buffer | ( | ) |
Create a new Buffer with the default size.
References _nbytes, and cygnal::NETBUFSIZE.
cygnal::Buffer::Buffer | ( | size_t | nbytes | ) |
cygnal::Buffer::Buffer | ( | const std::string & | str | ) |
cygnal::Buffer::~Buffer | ( | ) |
Delete the memory allocated for this Buffer.
References _data, _nbytes, _seekptr, and CLOCK_REALTIME.
size_t cygnal::Buffer::allocated | ( | ) | [inline] |
How much room has been allocated before the seek pointer. This is primarily used to see if the buffer is fully populated with data before appending more.
References _data.
Referenced by gnash::RTMPClient::clientFinish(), gnash::RTMP::decodeMsgBody(), gnash::HTTP::formatEchoResponse(), cygnal::EchoTest::formatEchoResponse(), cygnal::OflaDemoTest::formatOflaDemoResponse(), hexify(), operator+=(), gnash::RTMP::sendMsg(), cygnal::RTMPServer::sendToClient(), gnash::RTMP::split(), gnash::Network::writeNet(), gnash::DiskStream::writeToDisk(), and cygnal::Handler::writeToPlugin().
Buffer & cygnal::Buffer::append | ( | boost::uint8_t * | data, | |
size_t | nbytes | |||
) |
Append data to existing data in the buffer.
data | A pointer to the raw bytes to append to the buffer. | |
nbytes | The number of bytes to append. |
References _data, _seekptr, copy(), and spaceLeft().
Referenced by gnash::HTTP::formatEchoResponse(), and operator+=().
boost::uint8_t* cygnal::Buffer::at | ( | int | index | ) | [inline] |
Get the byte at a specified location.
index | The location as a numerical value of the byte to get. |
References _data.
boost::uint8_t* cygnal::Buffer::begin | ( | ) | [inline] |
Return the base address of the Buffer.
References _data.
Referenced by cygnal::RTMPServer::packetRead(), remove(), and cygnal::Handler::writeToPlugin().
void cygnal::Buffer::clear | ( | ) |
Clear the contents of the buffer by setting all the bytes to zeros.
References _data, _nbytes, and _seekptr.
Referenced by gnash::HTTP::clearHeader().
Buffer & cygnal::Buffer::copy | ( | boost::uint8_t * | data, | |
size_t | nbytes | |||
) |
Copy data into the buffer. This overwrites all data, and resets the seek ptr.
data | A pointer to the raw bytes to copy into the buffer. | |
nbytes | The number of bytes to copy. |
References _data, _nbytes, and _seekptr.
Referenced by append(), operator=(), remove(), and resize().
int cygnal::Buffer::corrupt | ( | int | factor | ) |
References _data, _nbytes, and gnash::key::i.
int cygnal::Buffer::corrupt | ( | ) |
Corrupt a buffer with random errors. This is used only for testing to make sure we can cleanly handle corruption of the packets.
factor | A divisor to adjust how many errors are created. |
factor | A divisor to adjust how many errors are created. |
void cygnal::Buffer::dump | ( | ) | const [inline] |
Dump the internal data of this class in a human readable form. This should only be used for debugging purposes.
References dump().
Referenced by dump(), and cygnal::operator<<().
void cygnal::Buffer::dump | ( | std::ostream & | os | ) | const |
bool cygnal::Buffer::empty | ( | ) | [inline] |
Test to see if the buffer has any data.
boost::uint8_t* cygnal::Buffer::end | ( | ) | [inline] |
Buffer & cygnal::Buffer::hex2mem | ( | const std::string & | str | ) |
Encode a Buffer from a hex string.
str | A hex string, ex... "00 03 05 0a" |
References end(), gnash::key::i, resize(), and size().
Referenced by Buffer().
std::string cygnal::Buffer::hexify | ( | ) |
Output a debug version of the Buffer's data. This just calls the gnash::Logfile::hexify(), but is more convienient as we don't have to extract the pointer and the byte count to hexify() a Buffer.
ascii | True if ASCII characters should be printed, false if only hex is desired. | |
buf | The buffer to hexify(). |
References _data, and allocated().
std::string cygnal::Buffer::hexify | ( | bool | ascii | ) |
References _data, allocated(), and hexify().
std::string cygnal::Buffer::hexify | ( | cygnal::Buffer & | buf, | |
bool | ascii | |||
) |
References allocated(), hexify(), and reference().
Buffer & cygnal::Buffer::operator+= | ( | cygnal::Element::amf0_type_e | type | ) |
Append an AMF0 type to existing data in the buffer.
Copy a AMF0 type into the buffer. This overwrites all data, and resets the seek ptr.
type | An AMF0 type. |
References operator+=().
Buffer & cygnal::Buffer::operator+= | ( | bool | flag | ) |
Append a boolean to existing data in the buffer.
type | A boolean. |
References operator+=().
Append a Buffer class to existing data in the buffer.
buf | A Buffer class containing the data to append. |
References allocated(), append(), and reference().
Referenced by operator+=().
Buffer & cygnal::Buffer::operator+= | ( | const std::string & | str | ) |
Buffer & cygnal::Buffer::operator+= | ( | const char * | str | ) |
Buffer & cygnal::Buffer::operator+= | ( | char | byte | ) |
Append a byte to existing data in the buffer.
byte | A single byte. |
References operator+=().
Buffer & cygnal::Buffer::operator+= | ( | double | num | ) |
Append a double to existing data in the buffer.
num | A numeric double value. |
References cygnal::AMF0_NUMBER_SIZE, and append().
Buffer & cygnal::Buffer::operator+= | ( | boost::uint32_t | length | ) |
Buffer & cygnal::Buffer::operator+= | ( | boost::uint16_t | length | ) |
Buffer & cygnal::Buffer::operator+= | ( | boost::uint8_t | byte | ) |
Buffer & cygnal::Buffer::operator= | ( | double | num | ) |
Copy a double into the buffer. This overwrites all data, and resets the seek ptr.
num | A numeric double value. |
References cygnal::AMF0_NUMBER_SIZE, and copy().
Buffer & cygnal::Buffer::operator= | ( | boost::uint16_t | length | ) |
Buffer & cygnal::Buffer::operator= | ( | boost::uint8_t | byte | ) |
Buffer & cygnal::Buffer::operator= | ( | boost::uint8_t * | data | ) |
Copy a Buffer class into the buffer. This overwrites all data, and resets the seek ptr.
Append a Buffer class to existing data in the buffer.
buf | A Buffer class containing the data to copy. |
buf | A Buffer class containing the data to append. |
References _nbytes, copy(), reference(), resize(), and size().
Referenced by operator=().
Buffer & cygnal::Buffer::operator= | ( | cygnal::Element::amf0_type_e | type | ) |
Copy a AMF0 type into the buffer. This overwrites all data, and resets the seek ptr.
type | An AMF0 type. |
References operator=().
Buffer & cygnal::Buffer::operator= | ( | bool | flag | ) |
Copy a boolean into the buffer. This overwrites all data, and resets the seek ptr.
flag | A boolean. |
References operator=().
Buffer & cygnal::Buffer::operator= | ( | const std::string & | str | ) |
bool cygnal::Buffer::operator== | ( | Buffer & | buf | ) |
Test equivalance against another Buffer. This compares all the data on the current Buffer with the supplied one, so it can be a performance hit. This is primarily only used for testing purposes.
buf | A reference to a Buffer. |
References _data, _nbytes, reference(), and size().
boost::uint8_t cygnal::Buffer::operator[] | ( | int | index | ) | [inline] |
Get the byte at a specified location.
index | The location as a numerical value of the byte to get. |
References _data.
const boost::uint8_t* cygnal::Buffer::reference | ( | ) | const [inline] |
References _data.
boost::uint8_t* cygnal::Buffer::reference | ( | ) | [inline] |
References _data.
Referenced by gnash::RTMPClient::clientFinish(), gnash::RTMP::decodeHeader(), gnash::RTMP::decodeMsgBody(), gnash::RTMP::decodePing(), gnash::RTMP::decodeUserControl(), cygnal::HTTPServer::extractRTMPT(), gnash::HTTP::formatEchoResponse(), cygnal::EchoTest::formatEchoResponse(), cygnal::OflaDemoTest::formatOflaDemoResponse(), hexify(), operator+=(), operator=(), operator==(), cygnal::RTMPServer::packetRead(), cygnal::AMF_msg::parseAMFPacket(), cygnal::AMF_msg::parseContextHeader(), cygnal::RTMPServer::parseEchoRequest(), gnash::HTTP::parseEchoRequest(), cygnal::EchoTest::parseEchoRequest(), cygnal::AMF_msg::parseMessageHeader(), cygnal::OflaDemoTest::parseOflaDemoRequest(), cygnal::HTTPServer::processClientRequest(), gnash::HTTP::processHeaderFields(), gnash::Network::readNet(), gnash::RTMP::sendMsg(), cygnal::RTMPServer::sendToClient(), gnash::RTMP::split(), gnash::Network::writeNet(), and gnash::DiskStream::writeToDisk().
boost::uint8_t * cygnal::Buffer::remove | ( | int | start | ) |
Drop a byte without resizing. This will remove the byte from the Buffer, and then move the remaining data to be in the correct location. This resets the seek pointer.
index | The location of the byte to remove from the Buffer |
start | The location of the byte to remove from the Buffer |
boost::uint8_t * cygnal::Buffer::remove | ( | int | start, | |
int | range | |||
) |
Drop bytes without resizing. This will remove the bytes from the Buffer, and then move the remaining data to be in the correct location. This resets the seek pointer.
index | The location of the byte to start removing data from the Buffer. This is an numerical value, not a pointer. | |
start | The location of the byte to remove from the Buffer | |
range | The amoiunt of bytes to remove from the Buffer. |
index | The location of the byte to start removing data from the Buffer. This is an numerical value, not a pointer. | |
start | The location of the byte to remove from the Buffer | |
range | The amount of bytes to remove from the Buffer. |
boost::uint8_t * cygnal::Buffer::remove | ( | boost::uint8_t | c | ) |
Drop a byte without resizing. This will remove the byte from the Buffer, and then move the remaining data to be in the correct location. This resets the seek pointer.
byte | The byte to remove from the buffer. |
References _data, _seekptr, begin(), copy(), end(), and start.
Buffer & cygnal::Buffer::resize | ( | ) |
Resize the buffer that holds the data. The new size of the current data is based on the current amount of data within the allocated memory. This is used to make a Buffer the same size as the existing data, and to truncate the unsed portion of the Buffer when copying to the new memory location.
References _data, and _seekptr.
Referenced by hex2mem(), operator=(), and gnash::Network::readNet().
Buffer & cygnal::Buffer::resize | ( | size_t | size | ) |
Resize the buffer that holds the data. If the size is larger than the existing data, the data is copied into the new region. If the size is smaller than the existing data, the remaining data is truncated when copying to the new memory location.
nbyte | The size to resize the Buffer to. |
void cygnal::Buffer::setPointer | ( | boost::uint8_t * | ptr | ) | [inline] |
Set the real pointer to a block of Memory.
References _data.
void cygnal::Buffer::setSeekPointer | ( | off_t | offset | ) | [inline] |
References _data.
void cygnal::Buffer::setSeekPointer | ( | boost::uint8_t * | ptr | ) | [inline] |
Set the seek pointer.
ptr | the real pointer to set the seek pointer to |
Referenced by gnash::Network::readNet().
void cygnal::Buffer::setSize | ( | size_t | nbytes | ) | [inline] |
size_t cygnal::Buffer::size | ( | ) | [inline] |
Get the size of the Buffer.
Referenced by hex2mem(), operator=(), operator==(), cygnal::RTMPServer::packetRead(), cygnal::AMF_msg::parseAMFPacket(), cygnal::AMF_msg::parseContextHeader(), cygnal::RTMPServer::parseEchoRequest(), gnash::HTTP::parseEchoRequest(), cygnal::EchoTest::parseEchoRequest(), cygnal::AMF_msg::parseMessageHeader(), cygnal::OflaDemoTest::parseOflaDemoRequest(), gnash::HTTP::processHeaderFields(), and gnash::Network::readNet().
size_t cygnal::Buffer::spaceLeft | ( | ) | [inline] |
cygnal::Buffer::_data [protected] |
This is the container of the actual data in this Buffer.
Referenced by append(), clear(), copy(), corrupt(), dump(), hexify(), operator+=(), operator=(), operator==(), remove(), resize(), and ~Buffer().
cygnal::Buffer::_nbytes [protected] |
This is the total allocated size of the Buffer.
Referenced by Buffer(), clear(), copy(), corrupt(), dump(), operator+=(), operator=(), operator==(), resize(), and ~Buffer().
cygnal::Buffer::_seekptr [protected] |