Skip to content

Commit

Permalink
utils: use std::copy for pack / unpack
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasDebrunner committed Dec 11, 2023
1 parent 528f2c4 commit 619d353
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions include/mav/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,16 +203,14 @@ namespace mav {
}


template<typename A, typename B>
A _packUnpack(B b) {
union U {
A a;
B b;
};
U u;
u.b = b;
return u.a;
template<typename To, typename From>
To _packUnpack(From o) {
static_assert(sizeof(To) == sizeof(From), "Cannot pack/unpack different sizes");
To result;
std::memcpy(&result, &o, sizeof(To));
return result;
}


template<typename T>
T floatUnpack(float f) {
Expand Down

0 comments on commit 619d353

Please sign in to comment.