2009-12-15 22:11:14 +00:00
|
|
|
#include <Endian/Endian.h>
|
2009-12-15 20:16:28 +00:00
|
|
|
|
2009-12-15 20:22:23 +00:00
|
|
|
namespace LittleEndian {
|
2009-12-15 20:16:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
uint16_t Read16(const void *vp)
|
|
|
|
{
|
|
|
|
const uint8_t *p = (const uint8_t *)vp;
|
|
|
|
return p[0] | (p[1] << 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Read24(const void *vp)
|
|
|
|
{
|
|
|
|
const uint8_t *p = (const uint8_t *)vp;
|
|
|
|
return (p[0]) | (p[1] << 8) | (p[2] << 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t Read32(const void *vp)
|
|
|
|
{
|
|
|
|
const uint8_t *p = (const uint8_t *)vp;
|
|
|
|
return (p[0]) | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Write16(void *vp, uint16_t x)
|
|
|
|
{
|
|
|
|
uint8_t *p = (uint8_t *)vp;
|
|
|
|
p[0] = (x) & 0xff;
|
|
|
|
p[1] = (x >> 8) & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Write24(void *vp, uint32_t x)
|
|
|
|
{
|
|
|
|
uint8_t *p = (uint8_t *)vp;
|
|
|
|
p[0] = (x) & 0xff;
|
|
|
|
p[1] = (x >> 8) & 0xff;
|
|
|
|
p[2] = (x >> 16) & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Write32(void *vp, uint32_t x)
|
|
|
|
{
|
|
|
|
uint8_t *p = (uint8_t *)vp;
|
|
|
|
p[0] = (x) & 0xff;
|
|
|
|
p[1] = (x >> 8) & 0xff;
|
|
|
|
p[2] = (x >> 16) & 0xff;
|
|
|
|
p[3] = (x >> 24) & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-12-15 20:22:23 +00:00
|
|
|
namespace BigEndian {
|
2009-12-15 20:16:28 +00:00
|
|
|
|
|
|
|
|
2009-12-19 23:59:31 +00:00
|
|
|
uint16_t Read16(const void *vp)
|
2009-12-15 20:16:28 +00:00
|
|
|
{
|
|
|
|
const uint8_t *p = (const uint8_t *)vp;
|
|
|
|
return (p[0] << 8) | (p[1]);
|
|
|
|
}
|
|
|
|
|
2009-12-19 23:59:31 +00:00
|
|
|
uint32_t Read24(const void *vp)
|
2009-12-15 20:16:28 +00:00
|
|
|
{
|
|
|
|
const uint8_t *p = (const uint8_t *)vp;
|
|
|
|
return (p[0] << 16) | (p[1] << 8) | (p[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-19 23:59:31 +00:00
|
|
|
uint32_t Read32(const void *vp)
|
2009-12-15 20:16:28 +00:00
|
|
|
{
|
|
|
|
const uint8_t *p = (const uint8_t *)vp;
|
|
|
|
return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | (p[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-19 23:59:31 +00:00
|
|
|
void Write16(void *vp, uint16_t x)
|
2009-12-15 20:16:28 +00:00
|
|
|
{
|
|
|
|
uint8_t *p = (uint8_t *)vp;
|
|
|
|
p[0] = (x >> 8) & 0xff;
|
|
|
|
p[1] = (x) & 0xff;
|
|
|
|
}
|
|
|
|
|
2009-12-19 23:59:31 +00:00
|
|
|
void Write24(void *vp, uint32_t x)
|
2009-12-15 20:16:28 +00:00
|
|
|
{
|
|
|
|
uint8_t *p = (uint8_t *)vp;
|
|
|
|
p[0] = (x >> 16) & 0xff;
|
|
|
|
p[1] = (x >> 8) & 0xff;
|
|
|
|
p[2] = (x) & 0xff;
|
|
|
|
}
|
|
|
|
|
2009-12-19 23:59:31 +00:00
|
|
|
void Write32(void *vp, uint32_t x)
|
2009-12-15 20:16:28 +00:00
|
|
|
{
|
|
|
|
uint8_t *p = (uint8_t *)vp;
|
|
|
|
p[0] = (x >> 24) & 0xff;
|
|
|
|
p[1] = (x >> 16) & 0xff;
|
|
|
|
p[2] = (x >> 8) & 0xff;
|
|
|
|
p[3] = (x) & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|