diff options
Diffstat (limited to 'Source/Utility/serialize.cpp')
-rw-r--r-- | Source/Utility/serialize.cpp | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/Source/Utility/serialize.cpp b/Source/Utility/serialize.cpp index b3e18429..41af9d3b 100644 --- a/Source/Utility/serialize.cpp +++ b/Source/Utility/serialize.cpp @@ -26,10 +26,10 @@ #include <cstring> -char to_hex( uint8_t v ) { - if( v <= 9 ) { +char to_hex(uint8_t v) { + if (v <= 9) { return '0' + v; - } else if( v < 16 ) { + } else if (v < 16) { return 'A' + v - 10; } else { return 'x'; @@ -37,9 +37,9 @@ char to_hex( uint8_t v ) { } uint8_t from_hex(char v) { - if( v >= '0' && v <= '9' ) { + if (v >= '0' && v <= '9') { return v - '0'; - } else if( v >= 'A' && v <= 'F' ) { + } else if (v >= 'A' && v <= 'F') { return v - 'A' + 10; } else { return 0; @@ -47,21 +47,20 @@ uint8_t from_hex(char v) { } int flags_to_string(char* dest, uint32_t val) { - dest[0] = to_hex( (val & 0xF0000000) >> 28); - dest[1] = to_hex( (val & 0x0F000000) >> 24); - dest[2] = to_hex( (val & 0x00F00000) >> 20); - dest[3] = to_hex( (val & 0x000F0000) >> 16); - dest[4] = to_hex( (val & 0x0000F000) >> 12); - dest[5] = to_hex( (val & 0x00000F00) >> 8); - dest[6] = to_hex( (val & 0x000000F0) >> 4); - dest[7] = to_hex( (val & 0x0000000F) >> 0); + dest[0] = to_hex((val & 0xF0000000) >> 28); + dest[1] = to_hex((val & 0x0F000000) >> 24); + dest[2] = to_hex((val & 0x00F00000) >> 20); + dest[3] = to_hex((val & 0x000F0000) >> 16); + dest[4] = to_hex((val & 0x0000F000) >> 12); + dest[5] = to_hex((val & 0x00000F00) >> 8); + dest[6] = to_hex((val & 0x000000F0) >> 4); + dest[7] = to_hex((val & 0x0000000F) >> 0); dest[8] = '\0'; return 0; } - -int string_flags_to_uint32(uint32_t* dest, const char* source ) { - if( strlen( source ) >= 8 ) { +int string_flags_to_uint32(uint32_t* dest, const char* source) { + if (strlen(source) >= 8) { *dest = 0x0; *dest |= ((uint32_t)from_hex(source[0])) << 28; *dest |= ((uint32_t)from_hex(source[1])) << 24; |