MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / build_table_cell_overflow

Function build_table_cell_overflow

internal/cbm/sqlite_writer.c:943–963  ·  view source on GitHub ↗

Build a table leaf cell with overflow: stores only the first local_len bytes of payload inline, followed by a 4-byte overflow page number. total_payload_len is the FULL original payload length (written as the payload-size varint so SQLite knows the real record size).

Source from the content-addressed store, hash-verified

941// total_payload_len is the FULL original payload length (written as the payload-size
942// varint so SQLite knows the real record size).
943static uint8_t *build_table_cell_overflow(int64_t rowid, const uint8_t *payload,
944 int total_payload_len, int local_len,
945 uint32_t overflow_page, int *out_cell_len) {
946 int rl = varint_len(total_payload_len);
947 int kl = varint_len(rowid);
948 // cell = varint(total_payload_len) + varint(rowid) + payload[0..local_len) + uint32(overflow)
949 int total = rl + kl + local_len + BTREE_PTR_SIZE;
950 uint8_t *cell = (uint8_t *)malloc(total);
951 if (!cell) {
952 return NULL;
953 }
954 int pos = 0;
955 pos += put_varint(cell + pos, total_payload_len);
956 pos += put_varint(cell + pos, rowid);
957 memcpy(cell + pos, payload, local_len);
958 pos += local_len;
959 put_u32(cell + pos, overflow_page);
960 pos += BTREE_PTR_SIZE;
961 *out_cell_len = pos;
962 return cell;
963}
964
965// --- Overflow page writer ---
966// Writes overflow pages for payload bytes that exceed local storage.

Callers 1

Calls 3

varint_lenFunction · 0.85
put_varintFunction · 0.85
put_u32Function · 0.85

Tested by

no test coverage detected