mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-27 09:21:43 +02:00
Add static_asserts to ser_X_to_Y() methods
This commit is contained in:
parent
be94096dfb
commit
0653939ac1
@ -142,24 +142,28 @@ inline uint64_t ser_double_to_uint64(double x)
|
|||||||
{
|
{
|
||||||
uint64_t tmp;
|
uint64_t tmp;
|
||||||
std::memcpy(&tmp, &x, sizeof(x));
|
std::memcpy(&tmp, &x, sizeof(x));
|
||||||
|
static_assert(sizeof(tmp) == sizeof(x), "double and uint64_t assumed to have the same size");
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
inline uint32_t ser_float_to_uint32(float x)
|
inline uint32_t ser_float_to_uint32(float x)
|
||||||
{
|
{
|
||||||
uint32_t tmp;
|
uint32_t tmp;
|
||||||
std::memcpy(&tmp, &x, sizeof(x));
|
std::memcpy(&tmp, &x, sizeof(x));
|
||||||
|
static_assert(sizeof(tmp) == sizeof(x), "float and uint32_t assumed to have the same size");
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
inline double ser_uint64_to_double(uint64_t y)
|
inline double ser_uint64_to_double(uint64_t y)
|
||||||
{
|
{
|
||||||
double tmp;
|
double tmp;
|
||||||
std::memcpy(&tmp, &y, sizeof(y));
|
std::memcpy(&tmp, &y, sizeof(y));
|
||||||
|
static_assert(sizeof(tmp) == sizeof(y), "double and uint64_t assumed to have the same size");
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
inline float ser_uint32_to_float(uint32_t y)
|
inline float ser_uint32_to_float(uint32_t y)
|
||||||
{
|
{
|
||||||
float tmp;
|
float tmp;
|
||||||
std::memcpy(&tmp, &y, sizeof(y));
|
std::memcpy(&tmp, &y, sizeof(y));
|
||||||
|
static_assert(sizeof(tmp) == sizeof(y), "float and uint32_t assumed to have the same size");
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user