From 6fdb82fa7f196173589ca281642ddc6ac6961005 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 27 Aug 2021 20:10:32 +0100 Subject: Extract and test time2From24bit --- lib/mysql_types.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'lib/mysql_types.cpp') diff --git a/lib/mysql_types.cpp b/lib/mysql_types.cpp index 8b2208e..40614ef 100644 --- a/lib/mysql_types.cpp +++ b/lib/mysql_types.cpp @@ -3,10 +3,21 @@ #include "rawDataReader.h" #include #include +#include #include #include namespace MyGrate::MySQL { +#define NTOH(B) \ + inline auto ntoh(uint##B##_t x) \ + { \ + if constexpr (__BYTE_ORDER == __LITTLE_ENDIAN) \ + x = bswap_##B(x); \ + return x; \ + } + NTOH(32); + NTOH(64); + typename Type::C Type::read(RawDataReader &, RawDataReader &) { @@ -153,10 +164,21 @@ namespace MyGrate::MySQL { return t; } + Time + time2From24bit(uint32_t tint) + { + Time t {}; + t.second = bitslice<6>(tint, 8); + t.minute = bitslice<6>(tint, 14); + t.hour = bitslice<5>(tint, 20); + return t; + } + typename Type::C - Type::read(RawDataReader &, RawDataReader &) + Type::read(RawDataReader & md, RawDataReader & data) { - throw std::logic_error("Not implemented"); + md.discard(1); + return time2From24bit(ntoh(data.readValue(3))); } typename Type::C -- cgit v1.2.3