From 473739b257dc50522a514ec5595eb47b94d01d9b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 28 Sep 2010 18:36:11 +0200 Subject: Extract bit-field in endian-portable manner --- mysql/types/test.hxx | 6 +++--- mysql/types/traits.hxx | 12 ++++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'mysql') diff --git a/mysql/types/test.hxx b/mysql/types/test.hxx index 8f3c632..d950a9a 100644 --- a/mysql/types/test.hxx +++ b/mysql/types/test.hxx @@ -38,7 +38,7 @@ struct date_time } bool - operator== (const date_time& y) + operator== (const date_time& y) const { return negative == y.negative && @@ -126,7 +126,7 @@ struct buffer } bool - operator== (const buffer& y) + operator== (const buffer& y) const { return size_ == y.size_ && std::memcmp (data_, y.data_, size_) == 0; } @@ -292,7 +292,7 @@ struct object string_ptr null_; bool - operator== (const object& y) + operator== (const object& y) const { return id_ == y.id_ && diff --git a/mysql/types/traits.hxx b/mysql/types/traits.hxx index 250343a..7d42798 100644 --- a/mysql/types/traits.hxx +++ b/mysql/types/traits.hxx @@ -108,9 +108,14 @@ namespace odb bool is_null) { if (!is_null) - std::memcpy (&v, s, 1); + { + v.a = *s & 1; + v.b = (*s >> 1) & 1; + v.c = (*s >> 2) & 1; + v.d = (*s >> 3) & 1; + } else - std::memset (&v, 0, sizeof (bitfield)); + v.a = v.b = v.c = v.d = 0; } static void @@ -122,8 +127,7 @@ namespace odb { is_null = false; n = 1; - std::memcpy (s, &v, 1); - s[0] &= 0x0F; // Clear unused bits -- MySQL is sensitive about that. + *s = v.a | (v.b << 1) | (v.c << 2) | (v.d << 3); } }; -- cgit v1.1