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

Function rec_finalize

internal/cbm/sqlite_writer.c:411–435  ·  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

409// Finalize: returns the complete record bytes (header_len + header + body).
410// Caller must free the returned buffer.
411static uint8_t *rec_finalize(RecordBuilder *r, int *out_len) {
412 *out_len = 0;
413 int header_content_len = r->header.len;
414 int header_len_varint_len = varint_len(header_content_len + varint_len(header_content_len));
415 // The header size varint includes itself, so we may need to iterate
416 int total_header = header_len_varint_len + header_content_len;
417 // Check if the header_len varint changes size when it includes itself
418 int recalc = varint_len(total_header);
419 if (recalc != header_len_varint_len) {
420 header_len_varint_len = recalc;
421 total_header = header_len_varint_len + header_content_len;
422 }
423
424 int total = total_header + r->body.len;
425 uint8_t *buf = (uint8_t *)malloc(total);
426 if (!buf) {
427 return NULL;
428 }
429 int pos = put_varint(buf, total_header);
430 memcpy(buf + pos, r->header.data, header_content_len);
431 pos += header_content_len;
432 memcpy(buf + pos, r->body.data, r->body.len);
433 *out_len = total;
434 return buf;
435}
436
437// --- Page builder ---
438// 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