Adding Spectre/System/ByteOrder
This commit is contained in:
parent
b0d14b91e0
commit
6f9b33be8f
3 changed files with 36 additions and 0 deletions
|
|
@ -27,6 +27,7 @@ settings.cc.includes:Add("vendor/stb/include")
|
|||
-----------------------------------------------------------
|
||||
|
||||
local system_module = Module("source/System", {
|
||||
"ByteOrder.cpp",
|
||||
"File.cpp",
|
||||
"Path.cpp",
|
||||
"MessageHandler.cpp",
|
||||
|
|
|
|||
15
include/Spectre/System/ByteOrder.h
Normal file
15
include/Spectre/System/ByteOrder.h
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
#ifndef SPECTRE_SYSTEM_BYTEORDER_H
|
||||
#define SPECTRE_SYSTEM_BYTEORDER_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace sp { namespace system
|
||||
{
|
||||
uint16_t ltoh16(const uint8_t* bytes);
|
||||
|
||||
uint32_t ltoh32(const uint8_t* bytes);
|
||||
|
||||
} } // namespace sp::system
|
||||
|
||||
#endif /* SPECTRE_SYSTEM_BYTEORDER_H */
|
||||
20
source/System/ByteOrder.cpp
Normal file
20
source/System/ByteOrder.cpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
#include <Spectre/System/ByteOrder.h>
|
||||
|
||||
namespace sp { namespace system
|
||||
{
|
||||
|
||||
uint16_t ltoh16(const uint8_t* bytes)
|
||||
{
|
||||
return bytes[0] | (bytes[1] << 8);
|
||||
}
|
||||
|
||||
uint32_t ltoh32(const uint8_t* bytes)
|
||||
{
|
||||
return bytes[0]
|
||||
| (bytes[1] << 8)
|
||||
| (bytes[2] << 16)
|
||||
| (bytes[3] << 24);
|
||||
}
|
||||
|
||||
} } // namespace sp::system
|
||||
Loading…
Add table
Add a link
Reference in a new issue