6#include "uperdecoder.h"
17UPERDecoder::~UPERDecoder() =
default;
19UPERDecoder::size_type UPERDecoder::offset()
const
24void UPERDecoder::seek(UPERDecoder::size_type index)
31 assert(minimum <= maximum);
32 const uint64_t range = maximum - minimum;
33 const size_type bits = 64 - std::countl_zero(range);
34 const auto result = m_data.valueAtMSB<int64_t>(m_idx, bits);
36 return result + minimum;
43 setError(
"Encountered INTEGER bigger than 64bit, not implemented.");
46 int64_t result = m_data.valueAtMSB<int64_t>(m_idx, 8 * len);
53 size_type len = m_data.valueAtMSB<size_type>(m_idx, 8);
55 if ((len & 0x80) == 0x00) {
58 if ((len & 0xc0) == 0x80) {
63 case 0xc1:
return 16384;
64 case 0xc2:
return 32768;
65 case 0xc3:
return 49152;
66 case 0xc4:
return 65536;
69 setError(
"Encountered invalid length determinant.");
83 return m_data.at(m_idx++) != 0;
86QByteArray UPERDecoder::readIA5StringData(size_type len)
90 for (size_type i = 0; i < len; ++i) {
91 const auto c = m_data.
valueAtMSB<
char>(m_idx, 7);
106 if (minLength == maxLength) {
111 return readIA5StringData(len);
117 const auto res = m_data.byteArrayAt(m_idx, len);
122QList<int> UPERDecoder::readSequenceOfConstrainedWholeNumber(int64_t minimum, int64_t maximum)
127 for (size_type i = 0; i < size; ++i) {
133QList<int> UPERDecoder::readSequenceOfUnconstrainedWholeNumber()
138 for (size_type i = 0; i < size; ++i) {
144QList<QByteArray> UPERDecoder::readSequenceOfIA5String()
147 QList<QByteArray> result;
149 for (size_type i = 0; i < size; ++i) {
155QList<QString> UPERDecoder::readSequenceOfUtf8String()
158 QList<QString> result;
160 for (size_type i = 0; i < size; ++i) {
168 return !m_error.isEmpty();
178 m_error =
"uPER decoding error at offset " +
QByteArray::number((qint64)m_idx) +
": " + msg;
Non-owning bit-level view for working with data that isn't byte-aligned.
T valueAtMSB(size_type index, size_type bits) const
Read a big endian unsigned number at bit offset index and bits in length.
int64_t readUnconstrainedWholeNumber()
Read unconstrained whole number.
void setError(const char *msg)
Put the decoder into the error state.
QString readUtf8String()
Read UTF-8 string.
QByteArray readOctetString()
Read unconstrained octet string (8 bit data).
bool readBoolean()
Read boolean value.
bool hasError() const
Reading at any point encountered an error.
QByteArray readIA5String()
Read an unconstrained IA5String (7 bit ASCII).
size_type readLengthDeterminant()
Read length determinant.
int64_t readConstrainedWholeNumber(int64_t minimum, int64_t maximum)
Read constrained whole number from the current position.
Classes for reservation/travel data models, data extraction and data augmentation.
QByteArray number(double n, char format, int precision)
void push_back(QByteArrayView str)
void reserve(qsizetype size)
void push_back(parameter_type value)
void reserve(qsizetype size)
QString fromUtf8(QByteArrayView str)