Blueprint: formatos de arquivo como interface (TbBpFormat)

JSON, XML e CSV são TbBpFormat (id, nome, extensão, write, read) numa
tabela; tb_blueprint_serialize/parse/format_name despacham por ela e há
tb_blueprint_format_for_path. O editor usa os ids TB_BP_FMT_* em vez de
um enum próprio duplicado.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mguinhosandClaude Opus 5.5 committed 2026-10-22 19:04:00 -03:00
1 parent 3b37ac7cd6
commit 27245d9080
5 files changed
+82 -29

No files matched your search

@@ -130,6 +130,19 @@ TinyBlocks_JsonValue* tb_blueprint_to_json(const TbBlueprint* bp);
TbBlueprint* tb_blueprint_from_json(const TinyBlocks_JsonValue* root);
/* Serializa para texto no formato pedido (malloc; libere com free). */
/* Formatos de arquivo como interface: cada um sabe escrever (e talvez ler)
um projeto. serialize/parse/save/load despacham pela tabela. */
typedef struct TbBpFormat {
int id; /* TB_BP_FMT_* */
const char* name; /* "json" */
const char* ext; /* ".json" */
char* (*write)(const TbBlueprint* bp, bool pretty); /* malloc */
TbBlueprint* (*read)(const char* text, char* err, size_t errcap); /* NULL = so exporta */
} TbBpFormat;
const TbBpFormat* tb_blueprint_format(int fmt); /* NULL se nao existe */
const TbBpFormat* tb_blueprint_format_for_path(const char* path); /* pela extensao */
char* tb_blueprint_serialize(const TbBlueprint* bp, int fmt, bool pretty);
/* Le do texto. Suporta o formato nativo (JSON). */
TbBlueprint* tb_blueprint_parse(const char* text, int fmt, char* err, size_t errcap);