mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-23 14:53:52 +00:00
Lots of stuff
This commit is contained in:
76
PortabilityLayer/BytePack.h
Normal file
76
PortabilityLayer/BytePack.h
Normal file
@@ -0,0 +1,76 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef __PL_BYTEPACK_H__
|
||||
#define __PL_BYTEPACK_H__
|
||||
|
||||
#include "DataTypes.h"
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
namespace BytePack
|
||||
{
|
||||
void BigUInt64(uint8_t *bytes, uint64_t value);
|
||||
void BigUInt32(uint8_t *bytes, uint32_t value);
|
||||
void BigUInt16(uint8_t *bytes, uint16_t value);
|
||||
}
|
||||
}
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
namespace BytePack
|
||||
{
|
||||
inline void BigUInt64(uint8_t *bytes, uint64_t value)
|
||||
{
|
||||
bytes[0] = static_cast<uint8_t>((value >> 56) & 0xff);
|
||||
bytes[1] = static_cast<uint8_t>((value >> 48) & 0xff);
|
||||
bytes[2] = static_cast<uint8_t>((value >> 40) & 0xff);
|
||||
bytes[3] = static_cast<uint8_t>((value >> 32) & 0xff);
|
||||
bytes[4] = static_cast<uint8_t>((value >> 24) & 0xff);
|
||||
bytes[5] = static_cast<uint8_t>((value >> 16) & 0xff);
|
||||
bytes[6] = static_cast<uint8_t>((value >> 8) & 0xff);
|
||||
bytes[7] = static_cast<uint8_t>(value & 0xff);
|
||||
}
|
||||
|
||||
inline void BigUInt32(uint8_t *bytes, uint32_t value)
|
||||
{
|
||||
bytes[0] = static_cast<uint8_t>((value >> 24) & 0xff);
|
||||
bytes[1] = static_cast<uint8_t>((value >> 16) & 0xff);
|
||||
bytes[2] = static_cast<uint8_t>((value >> 8) & 0xff);
|
||||
bytes[3] = static_cast<uint8_t>(value & 0xff);
|
||||
}
|
||||
|
||||
inline void BigUInt16(uint8_t *bytes, uint16_t value)
|
||||
{
|
||||
bytes[0] = static_cast<uint8_t>((value >> 8) & 0xff);
|
||||
bytes[1] = static_cast<uint8_t>(value & 0xff);
|
||||
}
|
||||
|
||||
inline void BigInt64(uint8_t *bytes, int64_t value)
|
||||
{
|
||||
bytes[0] = static_cast<uint8_t>((value >> 56) & 0xff);
|
||||
bytes[1] = static_cast<uint8_t>((value >> 48) & 0xff);
|
||||
bytes[2] = static_cast<uint8_t>((value >> 40) & 0xff);
|
||||
bytes[3] = static_cast<uint8_t>((value >> 32) & 0xff);
|
||||
bytes[4] = static_cast<uint8_t>((value >> 24) & 0xff);
|
||||
bytes[5] = static_cast<uint8_t>((value >> 16) & 0xff);
|
||||
bytes[6] = static_cast<uint8_t>((value >> 8) & 0xff);
|
||||
bytes[7] = static_cast<uint8_t>(value & 0xff);
|
||||
}
|
||||
|
||||
inline void BigInt32(uint8_t *bytes, uint32_t value)
|
||||
{
|
||||
bytes[0] = static_cast<uint8_t>((value >> 24) & 0xff);
|
||||
bytes[1] = static_cast<uint8_t>((value >> 16) & 0xff);
|
||||
bytes[2] = static_cast<uint8_t>((value >> 8) & 0xff);
|
||||
bytes[3] = static_cast<uint8_t>(value & 0xff);
|
||||
}
|
||||
|
||||
inline void BigInt16(uint8_t *bytes, uint16_t value)
|
||||
{
|
||||
bytes[0] = static_cast<uint8_t>((value >> 8) & 0xff);
|
||||
bytes[1] = static_cast<uint8_t>(value & 0xff);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user