mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
Interim but working support for crunched data streams when reading from the
device; writes haven't been converted yet. Reduces the bandiwidth from about 800kB/s to about 500kB/s, which is about what I thought.
This commit is contained in:
43
tests/crunch.cc
Normal file
43
tests/crunch.cc
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "globals.h"
|
||||
#include "bytes.h"
|
||||
#include "crunch.h"
|
||||
|
||||
static uint8_t outputbuffer[64];
|
||||
|
||||
static void test_crunch()
|
||||
{
|
||||
crunch_state_t cs = {};
|
||||
Bytes inputdata = { 0x01, 0x7f, 0x80, 0x81, 0x01 };
|
||||
cs.inputptr = inputdata.begin();
|
||||
cs.inputlen = inputdata.size();
|
||||
cs.outputptr = outputbuffer;
|
||||
cs.outputlen = 64;
|
||||
crunch(&cs);
|
||||
donecrunch(&cs);
|
||||
Bytes outputdata(outputbuffer, cs.outputptr - outputbuffer);
|
||||
|
||||
assert((outputdata == Bytes{ 0x01, 0x7f, 0xb0, 0x10 }));
|
||||
}
|
||||
|
||||
static void test_uncrunch()
|
||||
{
|
||||
crunch_state_t cs = {};
|
||||
Bytes inputdata = { 0x01, 0x7f, 0xb0, 0x10 };
|
||||
cs.inputptr = inputdata.begin();
|
||||
cs.inputlen = inputdata.size();
|
||||
cs.outputptr = outputbuffer;
|
||||
cs.outputlen = 64;
|
||||
uncrunch(&cs);
|
||||
doneuncrunch(&cs);
|
||||
Bytes outputdata(outputbuffer, cs.outputptr - outputbuffer);
|
||||
|
||||
assert((outputdata == Bytes { 0x01, 0x7f, 0x80, 0x81, 0x01 }));
|
||||
}
|
||||
|
||||
int main(int argc, const char* argv[])
|
||||
{
|
||||
test_crunch();
|
||||
test_uncrunch();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user