mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-06-17 06:11:03 +00:00
Fix bugs in ByteBuffer API and add BbAdvanceBuffer()
This commit is contained in:
+12
-3
@@ -1,8 +1,7 @@
|
|||||||
#include "ByteBuffer.h"
|
#include "ByteBuffer.h"
|
||||||
|
|
||||||
void BbInitializeWrappedBuffer(PBYTE_BUFFER buff, char* data, int offset, int length, int byteOrder) {
|
void BbInitializeWrappedBuffer(PBYTE_BUFFER buff, char* data, int offset, int length, int byteOrder) {
|
||||||
buff->buffer = data;
|
buff->buffer = data + offset;
|
||||||
buff->offset = offset;
|
|
||||||
buff->length = length;
|
buff->length = length;
|
||||||
buff->position = 0;
|
buff->position = 0;
|
||||||
buff->byteOrder = byteOrder;
|
buff->byteOrder = byteOrder;
|
||||||
@@ -38,6 +37,16 @@ static int byteSwapShort(PBYTE_BUFFER buff, short s) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int BbAdvanceBuffer(PBYTE_BUFFER buff, int offset) {
|
||||||
|
if (buff->position + offset > buff->length) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
buff->position += offset;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Get a byte from the byte buffer
|
// Get a byte from the byte buffer
|
||||||
int BbGet(PBYTE_BUFFER buff, char* c) {
|
int BbGet(PBYTE_BUFFER buff, char* c) {
|
||||||
if (buff->position + sizeof(*c) > buff->length) {
|
if (buff->position + sizeof(*c) > buff->length) {
|
||||||
@@ -52,7 +61,7 @@ int BbGet(PBYTE_BUFFER buff, char* c) {
|
|||||||
|
|
||||||
// Get a short from the byte buffer
|
// Get a short from the byte buffer
|
||||||
int BbGetShort(PBYTE_BUFFER buff, short* s) {
|
int BbGetShort(PBYTE_BUFFER buff, short* s) {
|
||||||
if (buff->position + sizeof(*s) >= buff->length) {
|
if (buff->position + sizeof(*s) > buff->length) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -19,13 +19,13 @@
|
|||||||
|
|
||||||
typedef struct _BYTE_BUFFER {
|
typedef struct _BYTE_BUFFER {
|
||||||
char* buffer;
|
char* buffer;
|
||||||
unsigned int offset;
|
|
||||||
unsigned int length;
|
unsigned int length;
|
||||||
unsigned int position;
|
unsigned int position;
|
||||||
unsigned int byteOrder;
|
unsigned int byteOrder;
|
||||||
} BYTE_BUFFER, *PBYTE_BUFFER;
|
} BYTE_BUFFER, *PBYTE_BUFFER;
|
||||||
|
|
||||||
void BbInitializeWrappedBuffer(PBYTE_BUFFER buff, char* data, int offset, int length, int byteOrder);
|
void BbInitializeWrappedBuffer(PBYTE_BUFFER buff, char* data, int offset, int length, int byteOrder);
|
||||||
|
int BbAdvanceBuffer(PBYTE_BUFFER buff, int offset);
|
||||||
|
|
||||||
int BbGet(PBYTE_BUFFER buff, char* c);
|
int BbGet(PBYTE_BUFFER buff, char* c);
|
||||||
int BbGetShort(PBYTE_BUFFER buff, short* s);
|
int BbGetShort(PBYTE_BUFFER buff, short* s);
|
||||||
|
|||||||
Reference in New Issue
Block a user