1#ifndef NEFORCE_NETWORK_HTTP_BYTE_CURSOR_HPP__
2#define NEFORCE_NETWORK_HTTP_BYTE_CURSOR_HPP__
14NEFORCE_BEGIN_NAMESPACE__
32 const byte_t* data_ =
nullptr;
40 size_t bits_in_buf_ = 0;
57 NEFORCE_NODISCARD
size_t remaining() const noexcept {
return size_ - pos_; }
61 NEFORCE_NODISCARD
bool exhausted() const noexcept {
return pos_ >= size_; }
63 NEFORCE_NODISCARD
const byte_t*
data() const noexcept {
return data_; }
65 NEFORCE_NODISCARD
size_t size() const noexcept {
return size_; }
94 if (pos_ + 2 > size_) {
107 if (pos_ + 3 > size_) {
120 if (pos_ + 4 > size_) {
133 if (pos_ + 8 > size_) {
146 if (pos_ + 2 > size_) {
159 if (pos_ + 4 > size_) {
172 if (pos_ + 8 > size_) {
186 if (pos_ +
count > size_) {
200 if (pos_ +
count > size_) {
229 while (bits_in_buf_ < n) {
234 bit_buf_ = (bit_buf_ << 8) | *b;
239 return (bit_buf_ >> bits_in_buf_) & mask;
248 if (n > 64 || bits_in_buf_ < n) {
252 return (bit_buf_ >> (bits_in_buf_ - n)) & mask;
260 if (n <= bits_in_buf_) {
268 NEFORCE_NODISCARD
size_t bits_remaining() const noexcept {
return bits_in_buf_; }
278 bit_buf_ = (bit_buf_ << 8) | data_[pos_++];
287NEFORCE_END_NAMESPACE__
optional< uint32_t > try_read_be32() noexcept
尝试读取大端序 32 位无符号整数
optional< byte_t > peek_byte() const noexcept
查看当前字节而不消费
optional< uint32_t > try_read_le32() noexcept
尝试读取小端序 32 位无符号整数
void skip_bits(uint8_t n) noexcept
跳过指定位数
optional< uint64_t > try_peek_bits(uint8_t n) const noexcept
预读指定位数而不消费
optional< uint64_t > try_read_le64() noexcept
尝试读取小端序 64 位无符号整数
optional< uint32_t > try_read_be24() noexcept
尝试读取大端序 24 位无符号整数
optional< cbyte_view > try_read_bytes(size_t count) noexcept
尝试读取指定长度的字节块
byte_cursor() noexcept=default
构造空游标
optional< uint16_t > try_read_be16() noexcept
尝试读取大端序 16 位无符号整数
bool exhausted() const noexcept
是否已读完所有数据
void reset(const byte_t *data, size_t size) noexcept
重置游标到新的缓冲区
size_t bits_remaining() const noexcept
位缓冲区中剩余的可读位数
optional< uint16_t > try_read_le16() noexcept
尝试读取小端序 16 位无符号整数
size_t size() const noexcept
获取底层缓冲区总大小
optional< uint64_t > try_read_be64() noexcept
尝试读取大端序 64 位无符号整数
const byte_t * data() const noexcept
获取底层数据指针
byte_cursor(cbyte_view view) noexcept
从 cbyte_view 构造
size_t remaining() const noexcept
剩余可读字节数
size_t consumed_bytes() const noexcept
已消费的字节数
bool refill_bits() noexcept
从字节缓冲区中补充位缓冲区
optional< byte_t > try_read_byte() noexcept
尝试读取一个字节
bool skip(size_t count) noexcept
跳过指定数量的字节
optional< uint64_t > try_read_bits(uint8_t n) noexcept
尝试读取指定位数(用于 HPACK Huffman 解码)
static constexpr T max() noexcept
获取类型的最大值
unsigned char byte_t
字节类型,定义为无符号字符
unsigned int uint32_t
32位无符号整数类型
unsigned long uint64_t
64位无符号整数类型
unsigned char uint8_t
8位无符号整数类型
unsigned short uint16_t
16位无符号整数类型
constexpr iter_difference_t< Iterator > count(Iterator first, Iterator last, const T &value)
统计范围内等于指定值的元素数量
memory_view< const byte_t > cbyte_view
常量字节视图类型别名
constexpr none_t none
默认空表示
static constexpr uint64_t read_be64(const byte_t *data) noexcept
读取64位大端整数
static constexpr uint16_t read_le16(const byte_t *data) noexcept
读取16位小端整数
static constexpr uint32_t read_le32(const byte_t *data) noexcept
读取32位小端整数
static constexpr uint16_t read_be16(const byte_t *data) noexcept
读取16位大端整数
static constexpr uint32_t read_be32(const byte_t *data) noexcept
读取32位大端整数
static constexpr uint64_t read_le64(const byte_t *data) noexcept
读取64位小端整数
static constexpr uint32_t read_be24(const byte_t *data) noexcept
读取24位大端整数