mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:14:59 +02:00
added bytes consumed result to decode, and exit early after bytes consumed
This commit is contained in:
parent
c0cdf3256c
commit
7790e35d24
3 changed files with 17 additions and 9 deletions
|
@ -1014,7 +1014,7 @@ void Application::paintGL() {
|
|||
|
||||
void Application::runTests() {
|
||||
runTimingTests();
|
||||
//runUnitTests();
|
||||
runUnitTests();
|
||||
}
|
||||
|
||||
void Application::audioMuteToggled() {
|
||||
|
|
|
@ -232,7 +232,7 @@ void runTimingTests() {
|
|||
(double)(elapsedUsecs / numTests), (double)result);
|
||||
|
||||
|
||||
quint64 BYTE_CODE_MAX_VALUE = 99999999;
|
||||
quint64 BYTE_CODE_MAX_TEST_VALUE = 99999999;
|
||||
quint64 BYTE_CODE_TESTS_SKIP = 999;
|
||||
|
||||
QByteArray extraJunk;
|
||||
|
@ -246,7 +246,7 @@ void runTimingTests() {
|
|||
startTime.start();
|
||||
quint64 tests = 0;
|
||||
quint64 failed = 0;
|
||||
for (quint64 value = 0; value < BYTE_CODE_MAX_VALUE; value += BYTE_CODE_TESTS_SKIP) {
|
||||
for (quint64 value = 0; value < BYTE_CODE_MAX_TEST_VALUE; value += BYTE_CODE_TESTS_SKIP) {
|
||||
quint64 valueA = value; // usecTimestampNow();
|
||||
ByteCountCoded<quint64> codedValueA = valueA;
|
||||
QByteArray codedValueABuffer = codedValueA;
|
||||
|
@ -328,9 +328,11 @@ void runUnitTests() {
|
|||
qDebug() << "codedValueBuffer:";
|
||||
outputBufferBits((const unsigned char*)codedValueBuffer.constData(), codedValueBuffer.size());
|
||||
|
||||
ByteCountCoded<quint64> valueDecoder = codedValueBuffer;
|
||||
ByteCountCoded<quint64> valueDecoder;
|
||||
size_t bytesConsumed = valueDecoder.decode(codedValueBuffer);
|
||||
quint64 valueDecoded = valueDecoder;
|
||||
qDebug() << "valueDecoded:" << valueDecoded;
|
||||
qDebug() << "bytesConsumed:" << bytesConsumed;
|
||||
|
||||
|
||||
if (value == valueDecoded) {
|
||||
|
|
|
@ -41,8 +41,8 @@ public:
|
|||
ByteCountCoded(const QByteArray& fromEncoded) : data(0) { decode(fromEncoded); }
|
||||
|
||||
QByteArray encode() const;
|
||||
void decode(const QByteArray& fromEncoded);
|
||||
void decode(const char* encodedBuffer, int encodedSize);
|
||||
size_t decode(const QByteArray& fromEncoded);
|
||||
size_t decode(const char* encodedBuffer, int encodedSize);
|
||||
|
||||
bool operator==(const ByteCountCoded& other) const { return data == other.data; }
|
||||
bool operator!=(const ByteCountCoded& other) const { return data != other.data; }
|
||||
|
@ -115,12 +115,13 @@ template<typename T> inline QByteArray ByteCountCoded<T>::encode() const {
|
|||
return output;
|
||||
}
|
||||
|
||||
template<typename T> inline void ByteCountCoded<T>::decode(const QByteArray& fromEncodedBytes) {
|
||||
decode(fromEncodedBytes.constData(), fromEncodedBytes.size());
|
||||
template<typename T> inline size_t ByteCountCoded<T>::decode(const QByteArray& fromEncodedBytes) {
|
||||
return decode(fromEncodedBytes.constData(), fromEncodedBytes.size());
|
||||
}
|
||||
|
||||
template<typename T> inline void ByteCountCoded<T>::decode(const char* encodedBuffer, int encodedSize) {
|
||||
template<typename T> inline size_t ByteCountCoded<T>::decode(const char* encodedBuffer, int encodedSize) {
|
||||
data = 0; // reset data
|
||||
size_t bytesConsumed = 0;
|
||||
int bitCount = BITS_IN_BYTE * encodedSize;
|
||||
|
||||
int encodedByteCount = 1; // there is at least 1 byte (after the leadBits)
|
||||
|
@ -133,6 +134,7 @@ template<typename T> inline void ByteCountCoded<T>::decode(const char* encodedBu
|
|||
|
||||
for(int byte = 0; byte < encodedSize; byte++) {
|
||||
char originalByte = encodedBuffer[byte];
|
||||
bytesConsumed++;
|
||||
unsigned char maskBit = 128; // LEFT MOST BIT set
|
||||
for(int bit = 0; bit < BITS_IN_BYTE; bit++) {
|
||||
bool bitIsSet = originalByte & maskBit;
|
||||
|
@ -165,7 +167,11 @@ template<typename T> inline void ByteCountCoded<T>::decode(const char* encodedBu
|
|||
bitAt++;
|
||||
maskBit = maskBit >> 1;
|
||||
}
|
||||
if (!inLeadBits && bitAt > lastValueBit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return bytesConsumed;
|
||||
}
|
||||
#endif // hifi_ByteCountCoding_h
|
||||
|
||||
|
|
Loading…
Reference in a new issue