diff --git a/includes/type/bcd.pat b/includes/type/bcd.pat new file mode 100644 index 0000000..f9b20f3 --- /dev/null +++ b/includes/type/bcd.pat @@ -0,0 +1,29 @@ +#pragma once + +#include + +namespace type { + + struct BCD { + u8 bytes[Digits]; + } [[sealed, format_read("type::impl::format_bcd")]]; + + namespace impl { + + fn format_bcd(ref auto bcd) { + str result; + + for (u32 i = 0, i < sizeof(bcd.bytes), i += 1) { + u8 byte = bcd.bytes[i]; + if (byte >= 10) + return "Invalid"; + + result += std::format("{}", byte); + } + + return result; + }; + + } + +}