mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-07-01 07:15:39 +00:00
Add ByteBuffer APIs for reading/writing multiple bytes
This commit is contained in:
parent
22a190bdd5
commit
84f37631c2
@ -47,18 +47,28 @@ bool BbAdvanceBuffer(PBYTE_BUFFER buff, int offset) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get a byte from the byte buffer
|
||||
bool BbGet8(PBYTE_BUFFER buff, uint8_t* c) {
|
||||
if (buff->position + sizeof(*c) > buff->length) {
|
||||
// Rewind the byte buffer back to the starting position
|
||||
void BbRewindBuffer(PBYTE_BUFFER buff) {
|
||||
buff->position = 0;
|
||||
}
|
||||
|
||||
// Get a variable number of bytes from the byte buffer (all or nothing though)
|
||||
bool BbGetBytes(PBYTE_BUFFER buff, uint8_t* data, int length) {
|
||||
if (buff->position + length > buff->length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(c, &buff->buffer[buff->position], sizeof(*c));
|
||||
buff->position += sizeof(*c);
|
||||
memcpy(data, &buff->buffer[buff->position], length);
|
||||
buff->position += length;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get a byte from the byte buffer
|
||||
bool BbGet8(PBYTE_BUFFER buff, uint8_t* c) {
|
||||
return BbGetBytes(buff, c, sizeof(*c));
|
||||
}
|
||||
|
||||
// Get a short from the byte buffer
|
||||
bool BbGet16(PBYTE_BUFFER buff, uint16_t* s) {
|
||||
if (buff->position + sizeof(*s) > buff->length) {
|
||||
@ -143,14 +153,19 @@ bool BbPut16(PBYTE_BUFFER buff, uint16_t s) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Put a byte into the buffer
|
||||
bool BbPut8(PBYTE_BUFFER buff, uint8_t c) {
|
||||
if (buff->position + sizeof(c) > buff->length) {
|
||||
// Put a variable number of bytes into the byte buffer (all or nothing though)
|
||||
bool BbPutBytes(PBYTE_BUFFER buff, const uint8_t* data, int length) {
|
||||
if (buff->position + length > buff->length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(&buff->buffer[buff->position], &c, sizeof(c));
|
||||
buff->position += sizeof(c);
|
||||
memcpy(&buff->buffer[buff->position], data, length);
|
||||
buff->position += length;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Put a byte into the buffer
|
||||
bool BbPut8(PBYTE_BUFFER buff, uint8_t c) {
|
||||
return BbPutBytes(buff, &c, sizeof(c));
|
||||
}
|
||||
|
@ -14,12 +14,15 @@ typedef struct _BYTE_BUFFER {
|
||||
|
||||
void BbInitializeWrappedBuffer(PBYTE_BUFFER buff, char* data, int offset, int length, int byteOrder);
|
||||
bool BbAdvanceBuffer(PBYTE_BUFFER buff, int offset);
|
||||
void BbRewindBuffer(PBYTE_BUFFER buff);
|
||||
|
||||
bool BbGetBytes(PBYTE_BUFFER buff, uint8_t* data, int length);
|
||||
bool BbGet8(PBYTE_BUFFER buff, uint8_t* c);
|
||||
bool BbGet16(PBYTE_BUFFER buff, uint16_t* s);
|
||||
bool BbGet32(PBYTE_BUFFER buff, uint32_t* i);
|
||||
bool BbGet64(PBYTE_BUFFER buff, uint64_t* l);
|
||||
|
||||
bool BbPutBytes(PBYTE_BUFFER buff, const uint8_t* data, int length);
|
||||
bool BbPut8(PBYTE_BUFFER buff, uint8_t c);
|
||||
bool BbPut16(PBYTE_BUFFER buff, uint16_t s);
|
||||
bool BbPut32(PBYTE_BUFFER buff, uint32_t i);
|
||||
|
@ -1059,12 +1059,8 @@ static void queueAsyncCallback(PNVCTL_ENET_PACKET_HEADER_V1 ctlHdr, int packetLe
|
||||
BbGet8(&bb, &queuedCb->data.dsAdaptiveTrigger.typeLeft);
|
||||
BbGet8(&bb, &queuedCb->data.dsAdaptiveTrigger.typeRight);
|
||||
|
||||
for(int i = 0; i < DS_EFFECT_PAYLOAD_SIZE; i++) {
|
||||
BbGet8(&bb, &queuedCb->data.dsAdaptiveTrigger.left[i]);
|
||||
}
|
||||
for(int i = 0; i < DS_EFFECT_PAYLOAD_SIZE; i++) {
|
||||
BbGet8(&bb, &queuedCb->data.dsAdaptiveTrigger.right[i]);
|
||||
}
|
||||
BbGetBytes(&bb, queuedCb->data.dsAdaptiveTrigger.left, DS_EFFECT_PAYLOAD_SIZE);
|
||||
BbGetBytes(&bb, queuedCb->data.dsAdaptiveTrigger.right, DS_EFFECT_PAYLOAD_SIZE);
|
||||
queuedCb->typeIndex = IDX_DS_ADAPTIVE_TRIGGERS;
|
||||
}
|
||||
else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user