[ox/std] Add UUID::toString variant that takes a Writer_c

This commit is contained in:
Gary Talent 2023-06-09 22:07:19 -05:00
parent fb43c956e7
commit bb85e6ab6c

View File

@ -145,6 +145,33 @@ class UUID {
return out;
}
[[nodiscard]]
constexpr ox::Error toString(Writer_c auto &writer) const noexcept {
auto valueI = 0u;
constexpr auto printChars = [](
Writer_c auto &writer,
const Array<uint8_t, 16> &value,
std::size_t cnt,
unsigned &valueI) {
for (auto i = 0u; i < cnt; ++i) {
const auto v = value[valueI];
const auto h = detail::toHex(v);
oxIgnoreError(writer.write(h.c_str(), h.len()));
++valueI;
}
};
printChars(writer, m_value, 4, valueI);
oxReturnError(writer.put('-'));
printChars(writer, m_value, 2, valueI);
oxReturnError(writer.put('-'));
printChars(writer, m_value, 2, valueI);
oxReturnError(writer.put('-'));
printChars(writer, m_value, 2, valueI);
oxReturnError(writer.put('-'));
printChars(writer, m_value, 6, valueI);
return {};
}
[[nodiscard]]
constexpr UUIDStr toString() const noexcept {
UUIDStr out;