Renamed HLAPI to VoidNet_HL and VoidNet to VoidNet_LL
This commit is contained in:
33
include/VoidNet_HL/ByteConverter.hpp
Normal file
33
include/VoidNet_HL/ByteConverter.hpp
Normal file
@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
// i want to use bitshifting but i red in stackoverflow that casting doesnt generate overhead
|
||||
// now ive hit a wall
|
||||
// casting vs bitshifting
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
namespace std
|
||||
{
|
||||
class ByteConverter
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
inline static uint8_t *ToBytes(T value)
|
||||
{
|
||||
uint8_t *data = new uint8_t[sizeof(T)]();
|
||||
memcpy(data, &value, sizeof(T));
|
||||
return data;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline static T FromBytes(uint8_t *data)
|
||||
{
|
||||
if (!data)
|
||||
throw std::invalid_argument("cant have null parameter -> ByteConverter::FromBytes");
|
||||
T value;
|
||||
memcpy(&value, data, sizeof(T));
|
||||
return value;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user