moonlight-common-c/src/ByteBuffer.h
2020-11-30 20:38:13 -06:00

38 lines
1.3 KiB
C

#pragma once
#include "Platform.h"
#define BYTE_ORDER_LITTLE 1
#define BYTE_ORDER_BIG 2
#ifndef HTONLL
#define HTONLL(x) \
((((x) & 0xff00000000000000ull) >> 56) \
| (((x) & 0x00ff000000000000ull) >> 40) \
| (((x) & 0x0000ff0000000000ull) >> 24) \
| (((x) & 0x000000ff00000000ull) >> 8) \
| (((x) & 0x00000000ff000000ull) << 8) \
| (((x) & 0x0000000000ff0000ull) << 24) \
| (((x) & 0x000000000000ff00ull) << 40) \
| (((x) & 0x00000000000000ffull) << 56))
#endif
typedef struct _BYTE_BUFFER {
char* buffer;
unsigned int length;
unsigned int position;
unsigned int byteOrder;
} BYTE_BUFFER, *PBYTE_BUFFER;
void BbInitializeWrappedBuffer(PBYTE_BUFFER buff, char* data, int offset, int length, int byteOrder);
bool BbAdvanceBuffer(PBYTE_BUFFER buff, int offset);
bool BbGet(PBYTE_BUFFER buff, char* c);
bool BbGetShort(PBYTE_BUFFER buff, short* s);
bool BbGetInt(PBYTE_BUFFER buff, int* i);
bool BbGetLong(PBYTE_BUFFER buff, long long* l);
bool BbPutInt(PBYTE_BUFFER buff, int i);
bool BbPutShort(PBYTE_BUFFER buff, short s);
bool BbPut(PBYTE_BUFFER buff, char c);
bool BbPutLong(PBYTE_BUFFER buff, long long l);