Signet Forge 0.1.0
C++20 Parquet library with AI-native extensions
DEMO
Loading...
Searching...
No Matches
signet::forge::thrift::CompactDecoder Class Reference

Thrift Compact Protocol reader. More...

#include <compact.hpp>

Public Member Functions

 CompactDecoder (const uint8_t *data, size_t size)
 Construct a decoder over a byte buffer.
 
FieldHeader read_field_header ()
 Read a field header.
 
bool read_bool ()
 Read a boolean value.
 
int8_t read_i8 ()
 Read an 8-bit signed integer (single raw byte, I8 wire type).
 
int32_t read_i32 ()
 Read a 32-bit integer (zigzag + varint decode).
 
int64_t read_i64 ()
 Read a 64-bit integer (zigzag + varint64 decode).
 
double read_double ()
 Read a double (8 bytes little-endian, IEEE 754).
 
float read_float ()
 Read a float (4 bytes little-endian, IEEE 754).
 
std::string read_string ()
 Read a string (varint-length-prefixed UTF-8 bytes).
 
std::vector< uint8_t > read_binary ()
 Read raw binary data (varint-length-prefixed bytes).
 
ListHeader read_list_header ()
 Read a list header. Returns element type and count.
 
void skip_field (uint8_t thrift_type)
 Skip a field without parsing its value.
 
void begin_struct ()
 Push a new field-ID context for reading a nested struct.
 
void end_struct ()
 Pop the field-ID context after finishing a nested struct.
 
size_t remaining () const
 Returns the number of bytes remaining in the buffer.
 
size_t position () const
 Returns the current read position (offset from start of buffer).
 
bool good () const
 Returns true if no errors have occurred (no bounds violations).
 

Detailed Description

Thrift Compact Protocol reader.

Reads Thrift Compact Protocol data from a caller-owned byte buffer. All read operations perform bounds checking and set an internal error flag on overflow, after which all subsequent reads return zero/empty values and good() returns false.

Hardening limits:

  • Maximum nesting depth: 128 (prevents stack exhaustion).
  • Maximum fields per struct: 65536 (prevents DoS via field-count inflation).
  • Maximum string/binary field: 64 MB (prevents memory exhaustion).
  • Maximum collection (LIST/SET/MAP) size: 1M entries.
See also
CompactEncoder for the corresponding writer

Definition at line 267 of file compact.hpp.

Constructor & Destructor Documentation

◆ CompactDecoder()

signet::forge::thrift::CompactDecoder::CompactDecoder ( const uint8_t *  data,
size_t  size 
)
inline

Construct a decoder over a byte buffer.

The buffer must remain valid for the lifetime of the decoder.

Parameters
dataPointer to the Thrift Compact Protocol byte buffer.
sizeTotal buffer size in bytes.

Definition at line 274 of file compact.hpp.

Member Function Documentation

◆ begin_struct()

void signet::forge::thrift::CompactDecoder::begin_struct ( )
inline

Push a new field-ID context for reading a nested struct.

Definition at line 508 of file compact.hpp.

◆ end_struct()

void signet::forge::thrift::CompactDecoder::end_struct ( )
inline

Pop the field-ID context after finishing a nested struct.

Definition at line 515 of file compact.hpp.

◆ good()

bool signet::forge::thrift::CompactDecoder::good ( ) const
inline

Returns true if no errors have occurred (no bounds violations).

Definition at line 531 of file compact.hpp.

◆ position()

size_t signet::forge::thrift::CompactDecoder::position ( ) const
inline

Returns the current read position (offset from start of buffer).

Definition at line 528 of file compact.hpp.

◆ read_binary()

std::vector< uint8_t > signet::forge::thrift::CompactDecoder::read_binary ( )
inline

Read raw binary data (varint-length-prefixed bytes).

Definition at line 390 of file compact.hpp.

◆ read_bool()

bool signet::forge::thrift::CompactDecoder::read_bool ( )
inline

Read a boolean value.

If the bool was embedded in a field header (types 1/2), returns that cached value. Otherwise reads a single byte.

Definition at line 332 of file compact.hpp.

◆ read_double()

double signet::forge::thrift::CompactDecoder::read_double ( )
inline

Read a double (8 bytes little-endian, IEEE 754).

Definition at line 358 of file compact.hpp.

◆ read_field_header()

FieldHeader signet::forge::thrift::CompactDecoder::read_field_header ( )
inline

Read a field header.

Returns {0, 0} for the STOP marker. For bool fields (types 1 and 2), the value is captured internally and returned by a subsequent read_bool() call.

Definition at line 285 of file compact.hpp.

◆ read_float()

float signet::forge::thrift::CompactDecoder::read_float ( )
inline

Read a float (4 bytes little-endian, IEEE 754).

Definition at line 369 of file compact.hpp.

◆ read_i32()

int32_t signet::forge::thrift::CompactDecoder::read_i32 ( )
inline

Read a 32-bit integer (zigzag + varint decode).

Definition at line 348 of file compact.hpp.

◆ read_i64()

int64_t signet::forge::thrift::CompactDecoder::read_i64 ( )
inline

Read a 64-bit integer (zigzag + varint64 decode).

Definition at line 353 of file compact.hpp.

◆ read_i8()

int8_t signet::forge::thrift::CompactDecoder::read_i8 ( )
inline

Read an 8-bit signed integer (single raw byte, I8 wire type).

Definition at line 342 of file compact.hpp.

◆ read_list_header()

ListHeader signet::forge::thrift::CompactDecoder::read_list_header ( )
inline

Read a list header. Returns element type and count.

Definition at line 400 of file compact.hpp.

◆ read_string()

std::string signet::forge::thrift::CompactDecoder::read_string ( )
inline

Read a string (varint-length-prefixed UTF-8 bytes).

Definition at line 380 of file compact.hpp.

◆ remaining()

size_t signet::forge::thrift::CompactDecoder::remaining ( ) const
inline

Returns the number of bytes remaining in the buffer.

Definition at line 523 of file compact.hpp.

◆ skip_field()

void signet::forge::thrift::CompactDecoder::skip_field ( uint8_t  thrift_type)
inline

Skip a field without parsing its value.

Used for forward compatibility when encountering unknown field IDs.

Definition at line 427 of file compact.hpp.


The documentation for this class was generated from the following file: