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:
David Given
2019-03-26 23:03:19 +01:00
parent 0453837c03
commit bcc5a5f2cd
13 changed files with 290 additions and 27 deletions

43
tests/crunch.cc Normal file
View 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;
}