Establish SQLite engine fork and Ziran varint decoder

This commit is contained in:
waozi committed 2026-11-22 06:04:38 -03:00
commit afd108cc74
2302 files changed
+1230001

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
// Decode one SQLite file-format varint and return the bytes consumed.
// The caller supplies at least available readable bytes and an aligned, writable u64.
// Zero denotes an incomplete input or a null pointer and leaves value untouched.
#program_export "ziran_sqlite_read_varint"
ReadVarint :: (bytes: *u8, available: usize, value: *u64) -> s32 {
if bytes == null || value == null { return 0 }
decoded: u64 = 0
offset: usize = 0
while offset < available && offset < 8 {
byte := bytes[offset]
decoded = (decoded << 7) | cast(u64)(byte & 0x7f)
offset += 1
if (byte & 0x80) == 0 {
<<value = decoded
return cast(s32)offset
}
}
// The ninth byte contributes all eight bits, including its high bit.
if available < 9 { return 0 }
<<value = (decoded << 8) | cast(u64)bytes[8]
return 9
}