mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-07-01 15:25:43 +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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a byte from the byte buffer
|
// Rewind the byte buffer back to the starting position
|
||||||
bool BbGet8(PBYTE_BUFFER buff, uint8_t* c) {
|
void BbRewindBuffer(PBYTE_BUFFER buff) {
|
||||||
if (buff->position + sizeof(*c) > buff->length) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(c, &buff->buffer[buff->position], sizeof(*c));
|
memcpy(data, &buff->buffer[buff->position], length);
|
||||||
buff->position += sizeof(*c);
|
buff->position += length;
|
||||||
|
|
||||||
return true;
|
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
|
// Get a short from the byte buffer
|
||||||
bool BbGet16(PBYTE_BUFFER buff, uint16_t* s) {
|
bool BbGet16(PBYTE_BUFFER buff, uint16_t* s) {
|
||||||
if (buff->position + sizeof(*s) > buff->length) {
|
if (buff->position + sizeof(*s) > buff->length) {
|
||||||
@ -143,14 +153,19 @@ bool BbPut16(PBYTE_BUFFER buff, uint16_t s) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put a byte into the buffer
|
// Put a variable number of bytes into the byte buffer (all or nothing though)
|
||||||
bool BbPut8(PBYTE_BUFFER buff, uint8_t c) {
|
bool BbPutBytes(PBYTE_BUFFER buff, const uint8_t* data, int length) {
|
||||||
if (buff->position + sizeof(c) > buff->length) {
|
if (buff->position + length > buff->length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&buff->buffer[buff->position], &c, sizeof(c));
|
memcpy(&buff->buffer[buff->position], data, length);
|
||||||
buff->position += sizeof(c);
|
buff->position += length;
|
||||||
|
|
||||||
return true;
|
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);
|
void BbInitializeWrappedBuffer(PBYTE_BUFFER buff, char* data, int offset, int length, int byteOrder);
|
||||||
bool BbAdvanceBuffer(PBYTE_BUFFER buff, int offset);
|
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 BbGet8(PBYTE_BUFFER buff, uint8_t* c);
|
||||||
bool BbGet16(PBYTE_BUFFER buff, uint16_t* s);
|
bool BbGet16(PBYTE_BUFFER buff, uint16_t* s);
|
||||||
bool BbGet32(PBYTE_BUFFER buff, uint32_t* i);
|
bool BbGet32(PBYTE_BUFFER buff, uint32_t* i);
|
||||||
bool BbGet64(PBYTE_BUFFER buff, uint64_t* l);
|
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 BbPut8(PBYTE_BUFFER buff, uint8_t c);
|
||||||
bool BbPut16(PBYTE_BUFFER buff, uint16_t s);
|
bool BbPut16(PBYTE_BUFFER buff, uint16_t s);
|
||||||
bool BbPut32(PBYTE_BUFFER buff, uint32_t i);
|
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.typeLeft);
|
||||||
BbGet8(&bb, &queuedCb->data.dsAdaptiveTrigger.typeRight);
|
BbGet8(&bb, &queuedCb->data.dsAdaptiveTrigger.typeRight);
|
||||||
|
|
||||||
for(int i = 0; i < DS_EFFECT_PAYLOAD_SIZE; i++) {
|
BbGetBytes(&bb, queuedCb->data.dsAdaptiveTrigger.left, DS_EFFECT_PAYLOAD_SIZE);
|
||||||
BbGet8(&bb, &queuedCb->data.dsAdaptiveTrigger.left[i]);
|
BbGetBytes(&bb, queuedCb->data.dsAdaptiveTrigger.right, DS_EFFECT_PAYLOAD_SIZE);
|
||||||
}
|
|
||||||
for(int i = 0; i < DS_EFFECT_PAYLOAD_SIZE; i++) {
|
|
||||||
BbGet8(&bb, &queuedCb->data.dsAdaptiveTrigger.right[i]);
|
|
||||||
}
|
|
||||||
queuedCb->typeIndex = IDX_DS_ADAPTIVE_TRIGGERS;
|
queuedCb->typeIndex = IDX_DS_ADAPTIVE_TRIGGERS;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user