Expand description
DuckDB VARCHAR (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 | unused: u32 ]
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::from_bytes(&bytes);
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.
Functions§
- read_
duck_ ⚠string - Reads a
DuckDBVARCHARvalue from a raw vector data pointer at a given row index.