fix schema description deser

This commit is contained in:
silverweed 2024-09-20 11:26:31 +02:00
parent ce4e84f8b1
commit 9e47b823f6

View file

@ -323,6 +323,7 @@ struct Sec_Hover_Fn {
b8 envelope_preamble() const b8 envelope_preamble() const
{ {
static const char *const envelope_names[] = { "INVALID", "Header", "Footer", "Page List" }; static const char *const envelope_names[] = { "INVALID", "Header", "Footer", "Page List" };
return titled_section("Envelope Preamble", [this] {
return field<u16>("Envelope type: %s", [] (Arena *arena, String8_Node *prev, const char *fmt, u16 val) { return field<u16>("Envelope type: %s", [] (Arena *arena, String8_Node *prev, const char *fmt, u16 val) {
const char *name = (val >= countof(envelope_names)) ? "Unknown" : envelope_names[val]; const char *name = (val >= countof(envelope_names)) ? "Unknown" : envelope_names[val];
return push_str8_node_child(arena, prev, fmt, name); return push_str8_node_child(arena, prev, fmt, name);
@ -332,14 +333,29 @@ struct Sec_Hover_Fn {
memcpy(&size, payload, 6); memcpy(&size, payload, 6);
return push_str8_node_child(arena, prev, fmt, to_pretty_size(arena, size)); return push_str8_node_child(arena, prev, fmt, to_pretty_size(arena, size));
}); });
});
} }
b8 list_frame_preamble() const b8 frame_header(const char *title = nullptr) const
{ {
return titled_section("Frame Preamble", [this] { String8 titlestr = title ? push_str8f(arena, "Frame Header: %s", title) : str8("Frame Header");
return field<i64>("Size: %" PRIi64, hover_display_val_le_abs<i64>) return titled_section(titlestr.c(), [this] {
|| field_le<u32>("N Items: %u") i64 size;
; memcpy(&size, data + start + cur_field_off, sizeof(size));
if (size >= 0)
return field<i64>("Record frame size: %" PRIi64 " B", hover_display_val_le_abs<i64>);
else if (roff < cur_field_off + 12) {
info.rng = { start + cur_field_off, 12 };
b8 ok = titled_section("List Frame", [this] {
add_to_desc<i64>("Size: %" PRIi64 " B", hover_display_val_le_abs<i64>);
add_to_desc<u32>("N Items: %u");
return true;
});
if (ok)
return ok;
}
cur_field_off += 12;
return false;
}); });
} }
@ -356,7 +372,7 @@ struct Sec_Hover_Fn {
if (roff < cur_field_off + field_desc_len) { if (roff < cur_field_off + field_desc_len) {
info.rng = { start + cur_field_off, (u64)field_desc_len }; info.rng = { start + cur_field_off, (u64)field_desc_len };
return titled_section("Field", [this] { return titled_section("Field", [this] {
add_to_desc<i64>("Size: %" PRIi64); add_to_desc<i64>("Size: %" PRIi64 " B");
add_to_desc<u32>("Field version: %u"); add_to_desc<u32>("Field version: %u");
add_to_desc<u32>("Type version: %u"); add_to_desc<u32>("Type version: %u");
add_to_desc<u32>("On-disk parent id: %u"); add_to_desc<u32>("On-disk parent id: %u");
@ -388,7 +404,7 @@ struct Sec_Hover_Fn {
u64 flags_off = start + cur_field_off + 22; u64 flags_off = start + cur_field_off + 22;
u16 flags; u16 flags;
memcpy(&flags, data + flags_off, sizeof(flags)); memcpy(&flags, data + flags_off, sizeof(flags));
b8 ok = field_le<i64>("Size: %" PRIi64) b8 ok = field_le<i64>("Size: %" PRIi64 " B")
|| field_le<u32>("Field version: %u") || field_le<u32>("Field version: %u")
|| field_le<u32>("Type version: %u") || field_le<u32>("Type version: %u")
|| field_le<u32>("On-disk parent id: %u") || field_le<u32>("On-disk parent id: %u")
@ -451,7 +467,7 @@ struct Sec_Hover_Fn {
u64 flags_off = start + cur_field_off + 16; u64 flags_off = start + cur_field_off + 16;
u16 flags; u16 flags;
memcpy(&flags, data + flags_off, sizeof(flags)); memcpy(&flags, data + flags_off, sizeof(flags));
b8 ok = field_le<i64>("Size: %" PRIi64) b8 ok = field_le<i64>("Size: %" PRIi64 " B")
|| field<u16>("Column Type: %s", [](Arena *arena, String8_Node *prev, const char *fmt, u16 val) { || field<u16>("Column Type: %s", [](Arena *arena, String8_Node *prev, const char *fmt, u16 val) {
const char *readable_col_type = get_column_type_name(val); const char *readable_col_type = get_column_type_name(val);
return push_str8_node_child(arena, prev, fmt, readable_col_type); return push_str8_node_child(arena, prev, fmt, readable_col_type);
@ -475,9 +491,9 @@ struct Sec_Hover_Fn {
} }
template <typename F> template <typename F>
b8 list_frame(F &&fn) const b8 list_frame(const char *title, F &&fn) const
{ {
if (list_frame_preamble()) if (frame_header(title))
return true; return true;
// we need to read back the number of entries to know how long is the next section. // we need to read back the number of entries to know how long is the next section.
u64 n_elems_off = cur_field_off - sizeof(u32); u64 n_elems_off = cur_field_off - sizeof(u32);
@ -492,17 +508,38 @@ struct Sec_Hover_Fn {
b8 schema_description(const char *title) const b8 schema_description(const char *title) const
{ {
return titled_section(title, [this] { return titled_section(title, [this] {
// Fields // TODO: Columns and alias columns are not the same
return list_frame([this] { return field_desc(); }) return list_frame("Fields", [this] { return field_desc(); })
|| list_frame([this] { return column_desc("Column"); }) || list_frame("Columns", [this] { return column_desc("Column"); })
|| list_frame([this] { return column_desc("Alias Column"); }) || list_frame("Alias Columns", [this] { return column_desc("Alias Column"); })
|| list_frame([this] { || list_frame("Extra Type Infos", [this] {
return field_le<u32>("Content identifier: %lu") return field_le<u32>("Content identifier: %lu")
|| field_le<u32>("Type version from: %lu") || field_le<u32>("Type version from: %lu")
|| field_le<u32>("Type version to: %lu"); || field_le<u32>("Type version to: %lu");
}); });
}); });
} }
b8 locator(const char *title) const
{
// TODO
return titled_section(title, [this] {
return true;
});
}
b8 cluster_group() const
{
return titled_section("Cluster Group", [this] {
return frame_header()
|| field_le<u64>("Min Entry: %" PRIu64)
|| field_le<u64>("Entry Span: %" PRIu64)
|| field_le<u32>("N Clusters: %u")
|| field_le<u64>("Env.Link Len: %" PRIu64)
|| locator("Env.Link Locator")
;
});
}
}; };
// `off` is the absolute offset into `data`. // `off` is the absolute offset into `data`.
@ -685,7 +722,10 @@ Sec_Hover_Info get_section_hover_info(Arena *arena, Section section, u64 off, co
|| hover.schema_description("Schema Extension") || hover.schema_description("Schema Extension")
// TODO: // TODO:
// - list of column group record frames // - list of column group record frames
|| hover.frame_header()
// - list of cluster group record frames // - list of cluster group record frames
|| hover.frame_header()
|| hover.cluster_group()
|| hover.range("Payload", section.range.len - hover.cur_field_off) || hover.range("Payload", section.range.len - hover.cur_field_off)
|| hover.field_le<u64>("Checksum: 0x%" PRIX64) || hover.field_le<u64>("Checksum: 0x%" PRIX64)
; ;