pg1003 / brle Goto Github PK
View Code? Open in Web Editor NEWA C++ library to compress or expand binary data using Run-Length Encoding
License: MIT License
A C++ library to compress or expand binary data using Run-Length Encoding
License: MIT License
Hello.
I've found an example of data, when encode-decode round trip does not give the identical result. It consists of four bytes: 0x00, 0x00, 0x80, 0x40
.
The patch to add this test case is:
diff --git a/tests/test.cpp b/tests/test.cpp
index 078a6d4..bc35c4f 100644
--- a/tests/test.cpp
+++ b/tests/test.cpp
@@ -52,6 +52,7 @@ static void encode_decode_uint8()
const uint8_t literalszeros[] = { 0x55, 0x00 };
const uint8_t literalsones[] = { 0xAA, 0xFF };
const uint8_t mixed[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x
FF, 0xAA, 0x00 };
+ const uint8_t weird[] = { 0x00, 0x00, 0x80, 0x40 };
assert_true( roundtrip( zeros, 0xFFu ) );
assert_true( roundtrip( ones ) );
@@ -63,6 +64,7 @@ static void encode_decode_uint8()
assert_true( roundtrip( literalszeros ) );
assert_true( roundtrip( literalsones ) );
assert_true( roundtrip( mixed ) );
+ assert_true( roundtrip( weird ) );
}
static void encode_decode_uint16()
The test program then produces this result:
> ./obj/test
check failed! (file tests/test.cpp, line 67): roundtrip( weird )
Total tests: 45, Tests failed: 1
It was possible to fix this with the following change:
diff --git a/src/brle.h b/src/brle.h
index 70f7b83..e4391ba 100644
--- a/src/brle.h
+++ b/src/brle.h
@@ -409,6 +409,10 @@ constexpr auto decode( InputIt input, InputIt last, OutputIt output ) -> OutputI
bit_count = bit_count - data_bits;
bits = in >> ( detail::literal_size - bit_count );
}
+
+ if( bit_count == 0) {
+ bits = 0;
+ }
}
return output;
But I am not completely sure if this is a correct approach.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.