Expand description
DuckDB VARCHAR and BLOB (duckdb_string_t) reading utilities.
§Pitfall P7: Undocumented duckdb_string_t format
DuckDB stores VARCHAR values in a 16-byte duckdb_string_t struct with two
representations:
- Inline (length ≤ 12):
[ len: u32 | data: [u8; 12] ] - Pointer (length > 12):
[ len: u32 | prefix: [u8; 4] | ptr: *const u8 ], the pointer at offset 8 (on a 32-bit target it takes 4 bytes and 4 bytes of padding follow)
This is not documented in the Rust bindings. The layout was determined by
reading DuckDB’s C source and confirmed by the duckdb-behavioral implementation.
§Example
use quack_rs::vector::string::{DuckStringView, read_duck_string};
// A short string (inline case)
let bytes: [u8; 16] = {
let mut b = [0u8; 16];
b[0] = 5; // length = 5
b[4..9].copy_from_slice(b"hello");
b
};
let view = DuckStringView::inline_from_bytes(&bytes).expect("inline value");
assert_eq!(view.as_str(), Some("hello"));
assert_eq!(view.len(), 5);Structs§
- Duck
String View - A parsed view of a
duckdb_string_tvalue.
Constants§
- DUCK_
STRING_ INLINE_ MAX_ LEN - The maximum string length that fits inline in a
duckdb_string_t(≤12 bytes). - DUCK_
STRING_ SIZE - The size of a
duckdb_string_tin bytes. - MAX_
STRING_ LEN - The longest
VARCHARorBLOBvalueDuckDBcan store, in bytes:string_t::MAX_STRING_SIZE, which isu32::MAXbecause the length field of aduckdb_string_tis au32.
Functions§
- check_
string_ len - Returns an error if
lenexceedsMAX_STRING_LEN. - read_
duck_ ⚠blob - Reads a
DuckDBBLOBvalue at the given row index. - read_
duck_ ⚠string - Reads a
DuckDBVARCHARvalue from a raw vector data pointer at a given row index.