Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
ByteConverter.h
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
6
#ifndef SKYFIRE_BYTECONVERTER_H
7
#define SKYFIRE_BYTECONVERTER_H
8
12
13
#include "
Define.h
"
14
#include <algorithm>
15
16
namespace
ByteConverter
17
{
18
template
<
size_t
T>
19
inline
void
convert
(
char
* val)
20
{
21
std::swap(*val, *(val + T - 1));
22
convert
<T - 2>(val + 1);
23
}
24
25
template
<>
inline
void
convert<0>
(
char
*) { }
26
template
<>
inline
void
convert<1>
(
char
*) { }
// ignore central byte
27
28
template
<
typename
T>
inline
void
apply
(T* val)
29
{
30
convert<sizeof(T)>
((
char
*)(val));
31
}
32
}
33
34
#if SKYFIRE_ENDIAN == SKYFIRE_BIGENDIAN
35
template
<
typename
T>
inline
void
EndianConvert
(T& val) {
ByteConverter::apply<T>
(&val); }
36
template
<
typename
T>
inline
void
EndianConvertReverse
(T&) { }
37
template
<
typename
T>
inline
void
EndianConvertPtr
(
void
* val) {
ByteConverter::apply<T>
(val); }
38
template
<
typename
T>
inline
void
EndianConvertPtrReverse
(
void
*) { }
39
#else
40
template
<
typename
T>
inline
void
EndianConvert
(T&) { }
41
template
<
typename
T>
inline
void
EndianConvertReverse
(T& val) {
ByteConverter::apply<T>
(&val); }
42
template
<
typename
T>
inline
void
EndianConvertPtr
(
void
*) { }
43
template
<
typename
T>
inline
void
EndianConvertPtrReverse
(
void
* val) {
ByteConverter::apply<T>
(val); }
44
#endif
45
46
template
<
typename
T>
void
EndianConvert
(T*);
// will generate link error
47
template
<
typename
T>
void
EndianConvertReverse
(T*);
// will generate link error
48
49
inline
void
EndianConvert
(
uint8
&) { }
50
inline
void
EndianConvert
(
int8
&) { }
51
inline
void
EndianConvertReverse
(
uint8
&) { }
52
inline
void
EndianConvertReverse
(
int8
&) { }
53
54
#endif
55
EndianConvertReverse
void EndianConvertReverse(T &val)
Definition
ByteConverter.h:41
EndianConvertPtr
void EndianConvertPtr(void *)
Definition
ByteConverter.h:42
EndianConvert
void EndianConvert(T &)
Definition
ByteConverter.h:40
EndianConvertPtrReverse
void EndianConvertPtrReverse(void *val)
Definition
ByteConverter.h:43
Define.h
uint8
std::uint8_t uint8
Definition
Define.h:79
int8
std::int8_t int8
Definition
Define.h:75
ByteConverter
Definition
ByteConverter.h:17
ByteConverter::convert< 1 >
void convert< 1 >(char *)
Definition
ByteConverter.h:26
ByteConverter::convert
void convert(char *val)
Definition
ByteConverter.h:19
ByteConverter::apply
void apply(T *val)
Definition
ByteConverter.h:28
ByteConverter::convert< 0 >
void convert< 0 >(char *)
Definition
ByteConverter.h:25
src
server
shared
Utilities
ByteConverter.h
Generated on
for Project SkyFire Core by
1.17.0