aboutsummaryrefslogtreecommitdiff
path: root/mysql/types/traits.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-09-28 18:36:11 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-09-28 18:36:11 +0200
commit473739b257dc50522a514ec5595eb47b94d01d9b (patch)
treefe298e4488677b8d795b86c45925febdb70dd085 /mysql/types/traits.hxx
parent0bda919deabcca2769088b90496538ea37393630 (diff)
Extract bit-field in endian-portable manner
Diffstat (limited to 'mysql/types/traits.hxx')
-rw-r--r--mysql/types/traits.hxx12
1 files changed, 8 insertions, 4 deletions
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);
}
};