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

Function snapshot_parse

src/discover/userconfig.c:626–656  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

624}
625
626static cbm_userconfig_snapshot_status_t snapshot_parse(CBMArena *arena, cbm_userconfig_t *cfg) {
627 cbm_userconfig_source_t *source = cfg->project_source;
628 yyjson_read_err error = {0};
629 yyjson_doc *doc = yyjson_read_opts((char *)source->bytes, source->len, 0, NULL, &error);
630 if (!doc)
631 return error.code == YYJSON_READ_ERROR_MEMORY_ALLOCATION ? CBM_USERCONFIG_SNAPSHOT_OOM
632 : CBM_USERCONFIG_SNAPSHOT_INVALID;
633 yyjson_val *extra = NULL;
634 cbm_userconfig_snapshot_status_t status = snapshot_extensions(yyjson_doc_get_root(doc), &extra);
635 size_t count = extra ? yyjson_obj_size(extra) : 0;
636 /* The 64 KiB source cap already bounds count; keep allocation math explicit. */
637 if (count > MAX_CONFIG_SIZE || count > SIZE_MAX / sizeof(*cfg->entries))
638 status = CBM_USERCONFIG_SNAPSHOT_LIMIT;
639 if (status == CBM_USERCONFIG_SNAPSHOT_OK && count > 0) {
640 cfg->entries = cbm_arena_calloc(arena, count * sizeof(*cfg->entries));
641 if (!cfg->entries)
642 status = CBM_USERCONFIG_SNAPSHOT_OOM;
643 }
644 if (status == CBM_USERCONFIG_SNAPSHOT_OK && extra) {
645 yyjson_obj_iter iter;
646 yyjson_obj_iter_init(extra, &iter);
647 yyjson_val *key;
648 while ((key = yyjson_obj_iter_next(&iter)) != NULL) {
649 status = snapshot_entry(arena, cfg, key, yyjson_obj_iter_get_val(key));
650 if (status != CBM_USERCONFIG_SNAPSHOT_OK)
651 break;
652 }
653 }
654 yyjson_doc_free(doc);
655 return status;
656}
657
658static cbm_userconfig_snapshot_status_t snapshot_input(cbm_userconfig_source_state_t state,
659 const void *bytes, size_t len) {

Callers 1

Calls 3

snapshot_extensionsFunction · 0.85
cbm_arena_callocFunction · 0.85
snapshot_entryFunction · 0.85

Tested by

no test coverage detected