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

Thrift Compact Protocol writer. More...

#include <compact.hpp>

Public Member Functions

 CompactEncoder ()
 Default constructor. Initializes field-ID stack with a single zero entry.
 
void write_field (int16_t field_id, uint8_t thrift_type)
 Write a field header.
 
void write_stop ()
 Write struct stop marker (0x00).
 
void begin_struct ()
 Push a new field-ID context for a nested struct.
 
void end_struct ()
 Pop the field-ID context after finishing a nested struct.
 
void write_bool (bool val)
 Write a standalone bool (not embedded in a field header).
 
void write_i8 (int8_t val)
 Write an 8-bit signed integer as a single raw byte (I8 wire type).
 
void write_field_bool (int16_t field_id, bool val)
 Write a bool field where the value is embedded in the field header's type nibble (1 = true, 2 = false).
 
void write_i32 (int32_t val)
 Write a 32-bit integer as zigzag + varint.
 
void write_i64 (int64_t val)
 Write a 64-bit integer as zigzag + varint.
 
void write_double (double val)
 Write a double as 8 bytes little-endian (IEEE 754).
 
void write_float (float val)
 Write a float as 4 bytes little-endian (IEEE 754).
 
void write_string (const std::string &val)
 Write a string as varint-length-prefixed UTF-8 bytes.
 
void write_binary (const uint8_t *data, size_t len)
 Write raw binary data as varint-length-prefixed bytes.
 
void write_list_header (uint8_t elem_type, int32_t size)
 Write a list header.
 
const std::vector< uint8_t > & data () const
 Returns a const reference to the underlying byte buffer.
 
size_t size () const
 Returns the current size of the encoded buffer in bytes.
 
void clear ()
 Resets the encoder to its initial state (empty buffer, field ID stack reset to a single zero entry).
 

Static Public Attributes

static constexpr size_t MAX_STRING_BYTES = 64u * 1024u * 1024u
 Maximum string/binary field size (matches CompactDecoder::MAX_STRING_BYTES).
 

Detailed Description

Thrift Compact Protocol writer.

Writes Thrift Compact Protocol data into an internal byte buffer. Supports nested structs, delta field encoding, zigzag+varint integers, and all standard compact types. Used to serialize Parquet FileMetaData and related structures.

See also
CompactDecoder for the corresponding reader
signet::forge::thrift (types.hpp) for Parquet-specific struct types

Definition at line 72 of file compact.hpp.

Constructor & Destructor Documentation

◆ CompactEncoder()

signet::forge::thrift::CompactEncoder::CompactEncoder ( )
inline

Default constructor. Initializes field-ID stack with a single zero entry.

Definition at line 78 of file compact.hpp.

Member Function Documentation

◆ begin_struct()

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

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

Definition at line 100 of file compact.hpp.

◆ clear()

void signet::forge::thrift::CompactEncoder::clear ( )
inline

Resets the encoder to its initial state (empty buffer, field ID stack reset to a single zero entry).

Definition at line 207 of file compact.hpp.

◆ data()

const std::vector< uint8_t > & signet::forge::thrift::CompactEncoder::data ( ) const
inline

Returns a const reference to the underlying byte buffer.

Definition at line 200 of file compact.hpp.

◆ end_struct()

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

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

Definition at line 103 of file compact.hpp.

◆ size()

size_t signet::forge::thrift::CompactEncoder::size ( ) const
inline

Returns the current size of the encoded buffer in bytes.

Definition at line 203 of file compact.hpp.

◆ write_binary()

void signet::forge::thrift::CompactEncoder::write_binary ( const uint8_t *  data,
size_t  len 
)
inline

Write raw binary data as varint-length-prefixed bytes.

Exceptions
std::overflow_errorif len > MAX_STRING_BYTES.

Definition at line 174 of file compact.hpp.

◆ write_bool()

void signet::forge::thrift::CompactEncoder::write_bool ( bool  val)
inline

Write a standalone bool (not embedded in a field header).

Definition at line 108 of file compact.hpp.

◆ write_double()

void signet::forge::thrift::CompactEncoder::write_double ( double  val)
inline

Write a double as 8 bytes little-endian (IEEE 754).

Definition at line 144 of file compact.hpp.

◆ write_field()

void signet::forge::thrift::CompactEncoder::write_field ( int16_t  field_id,
uint8_t  thrift_type 
)
inline

Write a field header.

Uses delta encoding when field_id - last_field_id is in [1, 15], otherwise writes the type byte followed by a zigzag varint of the field ID.

Definition at line 85 of file compact.hpp.

◆ write_field_bool()

void signet::forge::thrift::CompactEncoder::write_field_bool ( int16_t  field_id,
bool  val 
)
inline

Write a bool field where the value is embedded in the field header's type nibble (1 = true, 2 = false).

This is the standard compact protocol encoding for bool fields.

Definition at line 120 of file compact.hpp.

◆ write_float()

void signet::forge::thrift::CompactEncoder::write_float ( float  val)
inline

Write a float as 4 bytes little-endian (IEEE 754).

Note: Not part of standard Thrift compact protocol, but useful for Parquet FLOAT columns and other binary formats.

Definition at line 154 of file compact.hpp.

◆ write_i32()

void signet::forge::thrift::CompactEncoder::write_i32 ( int32_t  val)
inline

Write a 32-bit integer as zigzag + varint.

Definition at line 134 of file compact.hpp.

◆ write_i64()

void signet::forge::thrift::CompactEncoder::write_i64 ( int64_t  val)
inline

Write a 64-bit integer as zigzag + varint.

Definition at line 139 of file compact.hpp.

◆ write_i8()

void signet::forge::thrift::CompactEncoder::write_i8 ( int8_t  val)
inline

Write an 8-bit signed integer as a single raw byte (I8 wire type).

Definition at line 113 of file compact.hpp.

◆ write_list_header()

void signet::forge::thrift::CompactEncoder::write_list_header ( uint8_t  elem_type,
int32_t  size 
)
inline

Write a list header.

If size <= 14, uses the compact single-byte form. Otherwise writes (0xF0 | elem_type) followed by a varint size.

Definition at line 185 of file compact.hpp.

◆ write_stop()

void signet::forge::thrift::CompactEncoder::write_stop ( )
inline

Write struct stop marker (0x00).

Definition at line 97 of file compact.hpp.

◆ write_string()

void signet::forge::thrift::CompactEncoder::write_string ( const std::string &  val)
inline

Write a string as varint-length-prefixed UTF-8 bytes.

Exceptions
std::overflow_errorif val.size() > MAX_STRING_BYTES.

Definition at line 163 of file compact.hpp.

Member Data Documentation

◆ MAX_STRING_BYTES

constexpr size_t signet::forge::thrift::CompactEncoder::MAX_STRING_BYTES = 64u * 1024u * 1024u
staticconstexpr

Maximum string/binary field size (matches CompactDecoder::MAX_STRING_BYTES).

64 MB

Definition at line 75 of file compact.hpp.


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