mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-09 04:51:49 +00:00
minor refact
This commit is contained in:
parent
8c722b146e
commit
cd0ab951cf
1 changed files with 10 additions and 8 deletions
|
|
@ -15,21 +15,23 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool is_big_endian(void){
|
bool is_big_endian(void){
|
||||||
union {
|
uint32_t ui32_v = 0x01020304;
|
||||||
uint32_t i;
|
char bytes[sizeof(uint32_t)];
|
||||||
char c[4];
|
std::memcpy(bytes, &ui32_v, sizeof(uint32_t));
|
||||||
} bint = {0x01020304};
|
|
||||||
|
|
||||||
return bint.c[0] == 1;
|
return bytes[0] == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::int32_t convert_to_int(char* buffer, std::size_t len){
|
std::int32_t convert_to_int(char* buffer, std::size_t len){
|
||||||
std::int32_t a = 0;
|
std::int32_t a = 0;
|
||||||
if(!is_big_endian())
|
if (!is_big_endian()) {
|
||||||
std::memcpy(&a, buffer, len);
|
std::memcpy(&a, buffer, len);
|
||||||
else
|
}
|
||||||
for(std::size_t i = 0; i < len; ++i)
|
else {
|
||||||
|
for (std::size_t i = 0; i < len; ++i) {
|
||||||
reinterpret_cast<char*>(&a)[3 - i] = buffer[i];
|
reinterpret_cast<char*>(&a)[3 - i] = buffer[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue