diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-09-28 18:36:11 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-09-28 18:36:11 +0200 |
commit | 473739b257dc50522a514ec5595eb47b94d01d9b (patch) | |
tree | fe298e4488677b8d795b86c45925febdb70dd085 /mysql/types | |
parent | 0bda919deabcca2769088b90496538ea37393630 (diff) |
Extract bit-field in endian-portable manner
Diffstat (limited to 'mysql/types')
-rw-r--r-- | mysql/types/test.hxx | 6 | ||||
-rw-r--r-- | mysql/types/traits.hxx | 12 |
2 files changed, 11 insertions, 7 deletions
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); } }; |