mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-08-18 01:15:46 +00:00
Fix bugs in ByteBuffer API and add BbAdvanceBuffer()
This commit is contained in:
parent
dc21e28e1f
commit
924fdaf2db
@ -1,8 +1,7 @@
|
||||
#include "ByteBuffer.h"
|
||||
|
||||
void BbInitializeWrappedBuffer(PBYTE_BUFFER buff, char* data, int offset, int length, int byteOrder) {
|
||||
buff->buffer = data;
|
||||
buff->offset = offset;
|
||||
buff->buffer = data + offset;
|
||||
buff->length = length;
|
||||
buff->position = 0;
|
||||
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
|
||||
int BbGet(PBYTE_BUFFER buff, char* c) {
|
||||
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
|
||||
int BbGetShort(PBYTE_BUFFER buff, short* s) {
|
||||
if (buff->position + sizeof(*s) >= buff->length) {
|
||||
if (buff->position + sizeof(*s) > buff->length) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -144,4 +153,4 @@ int BbPut(PBYTE_BUFFER buff, char c) {
|
||||
buff->position += sizeof(c);
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -19,13 +19,13 @@
|
||||
|
||||
typedef struct _BYTE_BUFFER {
|
||||
char* buffer;
|
||||
unsigned int offset;
|
||||
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);
|
||||
int BbAdvanceBuffer(PBYTE_BUFFER buff, int offset);
|
||||
|
||||
int BbGet(PBYTE_BUFFER buff, char* c);
|
||||
int BbGetShort(PBYTE_BUFFER buff, short* s);
|
||||
|
Loading…
x
Reference in New Issue
Block a user