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

Function rec_finalize

internal/cbm/sqlite_writer.c:400–424  ·  view source on GitHub ↗

Finalize: returns the complete record bytes (header_len + header + body). Caller must free the returned buffer.

Source from the content-addressed store, hash-verified

398// Finalize: returns the complete record bytes (header_len + header + body).
399// Caller must free the returned buffer.
400static uint8_t *rec_finalize(RecordBuilder *r, int *out_len) {
401 *out_len = 0;
402 int header_content_len = r->header.len;
403 int header_len_varint_len = varint_len(header_content_len + varint_len(header_content_len));
404 // The header size varint includes itself, so we may need to iterate
405 int total_header = header_len_varint_len + header_content_len;
406 // Check if the header_len varint changes size when it includes itself
407 int recalc = varint_len(total_header);
408 if (recalc != header_len_varint_len) {
409 header_len_varint_len = recalc;
410 total_header = header_len_varint_len + header_content_len;
411 }
412
413 int total = total_header + r->body.len;
414 uint8_t *buf = (uint8_t *)malloc(total);
415 if (!buf) {
416 return NULL;
417 }
418 int pos = put_varint(buf, total_header);
419 memcpy(buf + pos, r->header.data, header_content_len);
420 pos += header_content_len;
421 memcpy(buf + pos, r->body.data, r->body.len);
422 *out_len = total;
423 return buf;
424}
425
426// --- Page builder ---
427// Accumulates cells (records) into B-tree leaf pages.

Callers 13

build_node_recordFunction · 0.85
build_edge_recordFunction · 0.85
build_vector_recordFunction · 0.85
build_token_vec_recordFunction · 0.85
build_project_recordFunction · 0.85
build_master_recordFunction · 0.85
ecell_url_pathFunction · 0.85
write_metadata_tablesFunction · 0.85

Calls 2

varint_lenFunction · 0.85
put_varintFunction · 0.85

Tested by

no test coverage detected