refactor/fix hover rootzip

This commit is contained in:
silverweed 2024-08-02 15:17:33 +02:00
parent e98777dc92
commit 6e30189b5a

View file

@ -523,17 +523,13 @@ String8_Node *display_val_rootzip(Arena *arena, String8_Node *prev, const char *
String8 zip_method; String8 zip_method;
if (src[0] == 'Z' && src[1] == 'L' && src[2] == Z_DEFLATED) { if (src[0] == 'Z' && src[1] == 'L' && src[2] == Z_DEFLATED) {
zip_method = str8("ZLIB"); zip_method = str8("ZLIB");
} } else if (src[0] == 'C' && src[1] == 'S' && src[2] == Z_DEFLATED) {
if (src[0] == 'C' && src[1] == 'S' && src[2] == Z_DEFLATED) {
zip_method = str8("Old"); zip_method = str8("Old");
} } else if (src[0] == 'X' && src[1] == 'Z' && src[2] == 0) {
if (src[0] == 'X' && src[1] == 'Z' && src[2] == 0) {
zip_method = str8("LZMA"); zip_method = str8("LZMA");
} } else if (src[0] == 'L' && src[1] == '4') {
if (src[0] == 'L' && src[1] == '4') {
zip_method = str8("LZ4"); zip_method = str8("LZ4");
} } else if (src[0] == 'Z' && src[1] == 'S' && src[2] == 1) {
if (src[0] == 'Z' && src[1] == 'S' && src[2] == 1) {
zip_method = str8("ZSTD"); zip_method = str8("ZSTD");
} else { } else {
return nullptr; return nullptr;
@ -567,7 +563,7 @@ struct Try_Sec_Hover_Fn {
u64 field_len = sizeof(T); u64 field_len = sizeof(T);
if (roff < cur_field_off + field_len) { if (roff < cur_field_off + field_len) {
info.rng = { start + cur_field_off, field_len }; info.rng = { start + cur_field_off, field_len };
TField_Type val; T val;
memcpy(&val, data + info.rng.start, info.rng.len); memcpy(&val, data + info.rng.start, info.rng.len);
display_val(arena, info.desc, desc_fmt, val); display_val(arena, info.desc, desc_fmt, val);
return true; return true;
@ -608,11 +604,29 @@ struct Try_Sec_Hover_Fn {
{ {
if (roff < cur_field_off + range_len) { if (roff < cur_field_off + range_len) {
info.rng = { start + cur_field_off, range_len }; info.rng = { start + cur_field_off, range_len };
return display_val(arena, info.desc, desc, data + start + cur_field_off); display_val(arena, info.desc, desc, data + start + cur_field_off);
return true;
} }
cur_field_off += range_len; cur_field_off += range_len;
return false; return false;
} }
b8 maybe_rootzip(const u8 *data, u64 start) const
{
// TODO boundary checks
const u64 range_len = 9;
if (display_val_rootzip(arena, info.desc, "Zipped Block", data + start + cur_field_off)) {
if (roff < cur_field_off + range_len) {
info.rng = { start + cur_field_off, range_len };
hover_display_val_be(arena, info.desc, "", data + start + cur_field_off);
return true;
}
// discard the description (it's fine since it's allocated in the scratch arena)
info.desc->first_child = nullptr;
cur_field_off += range_len;
}
return false;
}
}; };
internal internal
@ -660,13 +674,6 @@ b8 hover_try_key(const Try_Sec_Hover_Fn &try_sec_hover, const u8 *data, u64 star
} }
} }
internal
b8 hover_try_rootzip(const Try_Sec_Hover_Fn &try_sec_hover, const u8 *, u64)
{
// TODO boundary checks
return try_sec_hover.range_data("Zipped Block", 9, display_val_rootzip);
}
// `off` is the absolute offset into `data`. // `off` is the absolute offset into `data`.
internal internal
Sec_Hover_Info get_section_hover_info(Arena *arena, Section section, u64 off, const u8 *data) Sec_Hover_Info get_section_hover_info(Arena *arena, Section section, u64 off, const u8 *data)
@ -799,7 +806,7 @@ Sec_Hover_Info get_section_hover_info(Arena *arena, Section section, u64 off, co
case Sec_Page_List: case Sec_Page_List:
case Sec_Page: { case Sec_Page: {
hover_try_key(try_sec_hover, data, start) hover_try_key(try_sec_hover, data, start)
|| hover_try_rootzip(try_sec_hover, data, start) || try_sec_hover.maybe_rootzip(data, start)
|| try_sec_hover.range("Payload", section.range.len - section.post_size) // TODO: improve || try_sec_hover.range("Payload", section.range.len - section.post_size) // TODO: improve
|| try_sec_hover.field<u64>("Checksum: 0x%lX", hover_display_val_le) || try_sec_hover.field<u64>("Checksum: 0x%lX", hover_display_val_le)
; ;