summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-08-27 20:10:32 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-08-27 20:10:32 +0100
commit6fdb82fa7f196173589ca281642ddc6ac6961005 (patch)
tree90292fbf70fc2a0e6e6212743f74b74193af633a /lib
parentTest mod100_extract (diff)
downloadmygrate-6fdb82fa7f196173589ca281642ddc6ac6961005.tar.bz2
mygrate-6fdb82fa7f196173589ca281642ddc6ac6961005.tar.xz
mygrate-6fdb82fa7f196173589ca281642ddc6ac6961005.zip
Extract and test time2From24bit
Diffstat (limited to 'lib')
-rw-r--r--lib/mysql_types.cpp26
-rw-r--r--lib/mysql_types.h2
2 files changed, 26 insertions, 2 deletions
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 <algorithm>
#include <array>
+#include <byteswap.h>
#include <stdexcept>
#include <string>
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<MYSQL_TYPE_NULL, false>::C
Type<MYSQL_TYPE_NULL, false>::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<MYSQL_TYPE_TIME2>::C
- Type<MYSQL_TYPE_TIME2>::read(RawDataReader &, RawDataReader &)
+ Type<MYSQL_TYPE_TIME2>::read(RawDataReader & md, RawDataReader & data)
{
- throw std::logic_error("Not implemented");
+ md.discard(1);
+ return time2From24bit(ntoh(data.readValue<uint32_t>(3)));
}
typename Type<MYSQL_TYPE_DATE>::C
diff --git a/lib/mysql_types.h b/lib/mysql_types.h
index d32f6a8..d49cd2f 100644
--- a/lib/mysql_types.h
+++ b/lib/mysql_types.h
@@ -84,6 +84,8 @@ namespace MyGrate {
#undef DEFINE_USTYPE
#undef DEFINE_TYPE
+ Time time2From24bit(uint32_t tint);
+
struct ReplicationPosition {
#ifndef __cpp_aggregate_paren_init
ReplicationPosition(std::string f, uint64_t p) : filename {std::move(f)}, position {p} { }