|
trantor
Non-blocking I/O cross-platform TCP network library, using C++14
|
This class represents a memory buffer used for sending and receiving data. More...
#include <trantor/utils/MsgBuffer.h>
Public Member Functions | |
| MsgBuffer (size_t len=TRANTOR_BUFFER_DEFAULT_LENGTH) | |
| Construct a new message buffer instance. | |
| const char * | peek () const |
| Get the beginning of the buffer. | |
| const char * | beginWrite () const |
| Get the end of the buffer where new data can be written. | |
| char * | beginWrite () |
| uint8_t | peekInt8 () const |
| Get a byte value from the buffer. | |
| uint16_t | peekInt16 () const |
| Get a unsigned short value from the buffer. | |
| uint32_t | peekInt32 () const |
| Get a unsigned int value from the buffer. | |
| uint64_t | peekInt64 () const |
| Get a unsigned int64 value from the buffer. | |
| std::string | read (size_t len) |
| Get and remove some bytes from the buffer. | |
| uint8_t | readInt8 () |
| Get the remove a byte value from the buffer. | |
| uint16_t | readInt16 () |
| Get and remove a unsigned short value from the buffer. | |
| uint32_t | readInt32 () |
| Get and remove a unsigned int value from the buffer. | |
| uint64_t | readInt64 () |
| Get and remove a unsigned int64 value from the buffer. | |
| void | swap (MsgBuffer &buf) noexcept |
| swap the buffer with another. | |
| size_t | readableBytes () const |
| Return the size of the data in the buffer. | |
| size_t | writableBytes () const |
| Return the size of the empty part in the buffer. | |
| void | append (const MsgBuffer &buf) |
| Append new data to the buffer. | |
| template<int N> | |
| void | append (const char(&buf)[N]) |
| void | append (const char *buf, size_t len) |
| void | append (const std::string &buf) |
| void | appendInt8 (const uint8_t b) |
| Append a byte value to the end of the buffer. | |
| void | appendInt16 (const uint16_t s) |
| Append a unsigned short value to the end of the buffer. | |
| void | appendInt32 (const uint32_t i) |
| Append a unsigned int value to the end of the buffer. | |
| void | appendInt64 (const uint64_t l) |
| Append a unsigned int64 value to the end of the buffer. | |
| void | addInFront (const char *buf, size_t len) |
| Put new data to the beginning of the buffer. | |
| void | addInFrontInt8 (const uint8_t b) |
| Put a byte value to the beginning of the buffer. | |
| void | addInFrontInt16 (const uint16_t s) |
| Put a unsigned short value to the beginning of the buffer. | |
| void | addInFrontInt32 (const uint32_t i) |
| Put a unsigned int value to the beginning of the buffer. | |
| void | addInFrontInt64 (const uint64_t l) |
| Put a unsigned int64 value to the beginning of the buffer. | |
| void | retrieveAll () |
| Remove all data in the buffer. | |
| void | retrieve (size_t len) |
| Remove some bytes in the buffer. | |
| ssize_t | readFd (int fd, int *retErrno) |
| Read data from a file descriptor and put it into the buffer.˝ | |
| void | retrieveUntil (const char *end) |
| Remove the data before a certain position from the buffer. | |
| const char * | findCRLF () const |
| Find the position of the buffer where the CRLF is found. | |
| void | ensureWritableBytes (size_t len) |
| Make sure the buffer has enough spaces to write data. | |
| void | hasWritten (size_t len) |
| Move the write pointer forward when the new data has been written to the buffer. | |
| void | unwrite (size_t offset) |
| Move the write pointer backward to remove data in the end of the buffer. | |
| const char & | operator[] (size_t offset) const |
| Access a byte in the buffer. | |
| char & | operator[] (size_t offset) |
This class represents a memory buffer used for sending and receiving data.
|
explicit |
Construct a new message buffer instance.
| len | The initial size of the buffer. |
| void trantor::MsgBuffer::addInFront | ( | const char * | buf, |
| size_t | len ) |
Put new data to the beginning of the buffer.
| buf | |
| len |
| void trantor::MsgBuffer::addInFrontInt16 | ( | const uint16_t | s | ) |
Put a unsigned short value to the beginning of the buffer.
| s |
| void trantor::MsgBuffer::addInFrontInt32 | ( | const uint32_t | i | ) |
Put a unsigned int value to the beginning of the buffer.
| i |
| void trantor::MsgBuffer::addInFrontInt64 | ( | const uint64_t | l | ) |
Put a unsigned int64 value to the beginning of the buffer.
| l |
|
inline |
Put a byte value to the beginning of the buffer.
| b |
| void trantor::MsgBuffer::appendInt16 | ( | const uint16_t | s | ) |
Append a unsigned short value to the end of the buffer.
| s |
| void trantor::MsgBuffer::appendInt32 | ( | const uint32_t | i | ) |
Append a unsigned int value to the end of the buffer.
| i |
| void trantor::MsgBuffer::appendInt64 | ( | const uint64_t | l | ) |
Append a unsigned int64 value to the end of the buffer.
| l |
|
inline |
Append a byte value to the end of the buffer.
| b |
|
inline |
Get the end of the buffer where new data can be written.
| void trantor::MsgBuffer::ensureWritableBytes | ( | size_t | len | ) |
Make sure the buffer has enough spaces to write data.
| len |
|
inline |
Find the position of the buffer where the CRLF is found.
|
inline |
Move the write pointer forward when the new data has been written to the buffer.
| len |
|
inline |
Access a byte in the buffer.
| offset |
|
inline |
Get the beginning of the buffer.
| uint16_t trantor::MsgBuffer::peekInt16 | ( | ) | const |
Get a unsigned short value from the buffer.
| uint32_t trantor::MsgBuffer::peekInt32 | ( | ) | const |
Get a unsigned int value from the buffer.
| uint64_t trantor::MsgBuffer::peekInt64 | ( | ) | const |
Get a unsigned int64 value from the buffer.
|
inline |
Get a byte value from the buffer.
| std::string trantor::MsgBuffer::read | ( | size_t | len | ) |
Get and remove some bytes from the buffer.
| len |
|
inline |
Return the size of the data in the buffer.
| ssize_t trantor::MsgBuffer::readFd | ( | int | fd, |
| int * | retErrno ) |
Read data from a file descriptor and put it into the buffer.˝
| fd | The file descriptor. It is usually a socket. |
| retErrno | The error code when reading. |
| uint16_t trantor::MsgBuffer::readInt16 | ( | ) |
Get and remove a unsigned short value from the buffer.
| uint32_t trantor::MsgBuffer::readInt32 | ( | ) |
Get and remove a unsigned int value from the buffer.
| uint64_t trantor::MsgBuffer::readInt64 | ( | ) |
Get and remove a unsigned int64 value from the buffer.
| uint8_t trantor::MsgBuffer::readInt8 | ( | ) |
Get the remove a byte value from the buffer.
| void trantor::MsgBuffer::retrieve | ( | size_t | len | ) |
Remove some bytes in the buffer.
| len |
|
inline |
Remove the data before a certain position from the buffer.
| end | The position. |
|
noexcept |
swap the buffer with another.
| buf |
|
inline |
Move the write pointer backward to remove data in the end of the buffer.
| offset |
|
inline |
Return the size of the empty part in the buffer.