Adbase
Adinf C++ base library V2
|
Buffer 可以存取多种类型的数据,保证二进制安全,并且内存可以自动分配 More...
#include <Buffer.hpp>
Public Member Functions | |
Buffer (size_t initialSize=kInitialSize) | |
size_t | readableBytes () const |
获取 buffer 长度 More... | |
size_t | writableBytes () const |
获取 buffer 可写长度 More... | |
size_t | prependableBytes () const |
buffer 已读取向前可写长度 More... | |
const char * | peek () const |
获取 buffer 指针 More... | |
void | retrieve (size_t len) |
删除指定长度的数据 , 按照当前读取的指针位置向后删除, 当删除的长度大于 buffer 中的数据时会清空整个 buffer More... | |
void | retrieveUntil (const char *end) |
清空数据到指定位置 More... | |
void | retrieveInt64 () |
清空 int64_t 长度的数据 More... | |
void | retrieveInt32 () |
清空 int32_t 长度的数据 More... | |
void | retrieveInt16 () |
清空 int16_t 长度的数据 More... | |
void | retrieveInt8 () |
清空 int8_t 长度的数据 More... | |
void | retrieveAll () |
删除 buffer 中所有数据 More... | |
std::string | retrieveAllAsString () |
将 buffer 转化为 std::string 类型 More... | |
std::string | retrieveAsString (size_t len) |
将指定长度的 buffer 转化为 std::string 类型 More... | |
void | append (const std::string &str) |
添加 std::string 类型字符串到 buffer 中 More... | |
void | append (const char *data, size_t len) |
添加 char* 到 buffer 中 More... | |
void | append (const void *data, size_t len) |
添加 void* 到 buffer 中 More... | |
void | ensureWritableBytes (size_t len) |
确保 buffer 的写入空间够用,如果不够自动分配内存 More... | |
const char * | beginWrite () const |
char * | beginWrite () |
void | hasWritten (size_t len) |
void | appendInt64 (int64_t x) |
Append int64_t using network endian. More... | |
void | appendInt32 (int32_t x) |
Append int32_t using network endian. More... | |
void | appendInt16 (int16_t x) |
void | appendInt8 (int8_t x) |
int64_t | readInt64 () |
Read int64_t from network endian. More... | |
int32_t | readInt32 () |
Read int32_t from network endian. More... | |
int16_t | readInt16 () |
int8_t | readInt8 () |
int64_t | peekInt64 () const |
Peek int64_t from network endian. More... | |
int32_t | peekInt32 () const |
Peek int32_t from network endian. More... | |
int16_t | peekInt16 () const |
int8_t | peekInt8 () const |
void | prependInt64 (int64_t x) |
Prepend int64_t using network endian. More... | |
void | prependInt32 (int32_t x) |
Prepend int32_t using network endian. More... | |
void | prependInt16 (int16_t x) |
void | prependInt8 (int8_t x) |
void | prepend (const void *data, size_t len) |
void | shrink () |
size_t | internalCapacity () const |
Static Public Attributes | |
static const size_t | kInitialSize = 1024 |
Buffer 可以存取多种类型的数据,保证二进制安全,并且内存可以自动分配
Definition at line 34 of file Buffer.hpp.
|
inlineexplicit |
Definition at line 38 of file Buffer.hpp.
|
inline |
添加 std::string 类型字符串到 buffer 中
Definition at line 118 of file Buffer.hpp.
Referenced by append(), appendInt16(), appendInt32(), appendInt64(), appendInt8(), adbase::mc::ClientHandler::get(), adbase::mc::Ascii::processData(), adbase::mc::Context::setAsciiBuffer(), and adbase::kafka::Consumer::threadFunc().
|
inline |
添加 char* 到 buffer 中
Definition at line 123 of file Buffer.hpp.
References beginWrite(), ensureWritableBytes(), and hasWritten().
|
inline |
|
inline |
Definition at line 169 of file Buffer.hpp.
References append(), and adbase::hostToNetwork16().
|
inline |
Append int32_t using network endian.
Definition at line 164 of file Buffer.hpp.
References append(), and adbase::hostToNetwork32().
|
inline |
Append int64_t using network endian.
Definition at line 156 of file Buffer.hpp.
References append(), and adbase::hostToNetwork64().
|
inline |
Definition at line 174 of file Buffer.hpp.
References append().
|
inline |
Definition at line 141 of file Buffer.hpp.
Referenced by append().
|
inline |
Definition at line 145 of file Buffer.hpp.
|
inline |
确保 buffer 的写入空间够用,如果不够自动分配内存
Definition at line 135 of file Buffer.hpp.
References writableBytes().
Referenced by append().
|
inline |
Definition at line 149 of file Buffer.hpp.
Referenced by append().
|
inline |
Definition at line 281 of file Buffer.hpp.
References prependableBytes(), readableBytes(), and writableBytes().
|
inline |
获取 buffer 指针
Definition at line 60 of file Buffer.hpp.
Referenced by adbase::mc::Context::getAsciiBuffer(), adbase::mc::ClientHandler::onConnection(), peekInt16(), peekInt32(), peekInt64(), peekInt8(), adbase::mc::Ascii::processData(), adbase::head::Binary::processData(), adbase::mc::Binary::processData(), retrieveAsString(), retrieveUntil(), and adbase::kafka::Producer::threadFunc().
|
inline |
Definition at line 232 of file Buffer.hpp.
References adbase::networkToHost16(), peek(), and readableBytes().
Referenced by readInt16().
|
inline |
Peek int32_t from network endian.
Require: buf->readableBytes() >= sizeof(int32_t)
Definition at line 225 of file Buffer.hpp.
References adbase::networkToHost32(), peek(), and readableBytes().
Referenced by readInt32().
|
inline |
Peek int64_t from network endian.
Require: buf->readableBytes() >= sizeof(int64_t)
Definition at line 214 of file Buffer.hpp.
References adbase::networkToHost64(), peek(), and readableBytes().
Referenced by readInt64().
|
inline |
Definition at line 239 of file Buffer.hpp.
References peek(), and readableBytes().
Referenced by readInt8().
|
inline |
Definition at line 270 of file Buffer.hpp.
References prependableBytes().
Referenced by prependInt16(), prependInt32(), prependInt64(), and prependInt8().
|
inline |
buffer 已读取向前可写长度
Definition at line 55 of file Buffer.hpp.
Referenced by internalCapacity(), and prepend().
|
inline |
Definition at line 261 of file Buffer.hpp.
References adbase::hostToNetwork16(), and prepend().
|
inline |
Prepend int32_t using network endian.
Definition at line 256 of file Buffer.hpp.
References adbase::hostToNetwork32(), and prepend().
|
inline |
Prepend int64_t using network endian.
Definition at line 248 of file Buffer.hpp.
References adbase::hostToNetwork64(), and prepend().
|
inline |
Definition at line 266 of file Buffer.hpp.
References prepend().
|
inline |
获取 buffer 长度
Definition at line 45 of file Buffer.hpp.
Referenced by adbase::mc::ClientHandler::get(), adbase::mc::Context::getAsciiBuffer(), adbase::mc::Context::getAsciiBufferSize(), internalCapacity(), adbase::mc::ClientHandler::onConnection(), peekInt16(), peekInt32(), peekInt64(), peekInt8(), adbase::mc::Ascii::processData(), adbase::head::Binary::processData(), adbase::mc::Binary::processData(), retrieve(), retrieveAllAsString(), and adbase::kafka::Producer::threadFunc().
|
inline |
Definition at line 198 of file Buffer.hpp.
References peekInt16(), and retrieveInt16().
|
inline |
Read int32_t from network endian.
Require: buf->readableBytes() >= sizeof(int32_t)
Definition at line 192 of file Buffer.hpp.
References peekInt32(), and retrieveInt32().
|
inline |
Read int64_t from network endian.
Require: buf->readableBytes() >= sizeof(int32_t)
Definition at line 182 of file Buffer.hpp.
References peekInt64(), and retrieveInt64().
|
inline |
Definition at line 204 of file Buffer.hpp.
References peekInt8(), and retrieveInt8().
|
inline |
删除指定长度的数据 , 按照当前读取的指针位置向后删除, 当删除的长度大于 buffer 中的数据时会清空整个 buffer
Definition at line 66 of file Buffer.hpp.
References readableBytes(), and retrieveAll().
Referenced by adbase::mc::Context::getAsciiBuffer(), adbase::mc::Ascii::processData(), retrieveAsString(), retrieveInt16(), retrieveInt32(), retrieveInt64(), retrieveInt8(), and retrieveUntil().
|
inline |
删除 buffer 中所有数据
Definition at line 100 of file Buffer.hpp.
Referenced by adbase::mc::ClientHandler::get(), adbase::mc::ClientHandler::onConnection(), adbase::head::Binary::processData(), adbase::mc::Binary::processData(), retrieve(), and adbase::kafka::Consumer::threadFunc().
|
inline |
将 buffer 转化为 std::string 类型
Definition at line 106 of file Buffer.hpp.
References readableBytes(), and retrieveAsString().
Referenced by adbase::mc::ClientHandler::get(), and adbase::mc::Ascii::processData().
|
inline |
将指定长度的 buffer 转化为 std::string 类型
Definition at line 111 of file Buffer.hpp.
References peek(), and retrieve().
Referenced by retrieveAllAsString().
|
inline |
清空 int16_t 长度的数据
Definition at line 90 of file Buffer.hpp.
References retrieve().
Referenced by readInt16().
|
inline |
清空 int32_t 长度的数据
Definition at line 85 of file Buffer.hpp.
References retrieve().
Referenced by readInt32().
|
inline |
清空 int64_t 长度的数据
Definition at line 80 of file Buffer.hpp.
References retrieve().
Referenced by readInt64().
|
inline |
清空 int8_t 长度的数据
Definition at line 95 of file Buffer.hpp.
References retrieve().
Referenced by readInt8().
|
inline |
|
inline |
Definition at line 277 of file Buffer.hpp.
|
inline |
获取 buffer 可写长度
Definition at line 50 of file Buffer.hpp.
Referenced by ensureWritableBytes(), and internalCapacity().
|
static |
Definition at line 36 of file Buffer.hpp.