7#include "vendor0080block.h"
8#include "vendor0080vublockdata.h"
9#include "uic9183utils.h"
17 SBlockFirstByte =
'S',
19 SBlockLengthOffset = 4,
54Vendor0080BLSubBlock::Vendor0080BLSubBlock() =
default;
56Vendor0080BLSubBlock::Vendor0080BLSubBlock(
const Uic9183Block &block,
int offset)
63 if (block.
contentSize() < offset + SBlockHeaderSize) {
64 qCWarning(Log) <<
"0080BL S-block too small";
67 if (*(block.
content() + offset) != SBlockFirstByte) {
68 qCWarning(Log) <<
"0080BL invalid S-block header";
74 qCWarning(
Log) <<
"0080BL S-block size exceeds 0080BL block size";
79bool Vendor0080BLSubBlock::isNull()
const
81 return m_block.isNull();
91 if (m_offset +
size() >= m_block.contentSize()) {
94 return Vendor0080BLSubBlock(m_block, m_offset +
size());
102 return Uic9183Utils::readAsciiEncodedNumber(m_block.content(), m_block.size(), m_offset + SBlockLengthOffset, SBlockLengthSize);
110 return m_block.content() + m_offset + SBlockTypeOffset;
113const char* Vendor0080BLSubBlock::content()
const
118 return m_block.content() + m_offset + SBlockHeaderSize;
130Vendor0080BLOrderBlock::Vendor0080BLOrderBlock() =
default;
131Vendor0080BLOrderBlock::Vendor0080BLOrderBlock(
const Uic9183Block &block,
int offset)
137bool Vendor0080BLOrderBlock::isNull()
const
142QDate Vendor0080BLOrderBlock::validFrom()
const
144 switch (m_block.version()) {
146 return QDate::fromString(Uic9183Utils::readUtf8String(m_block, m_offset + 22, 8), QStringLiteral(
"ddMMyyyy"));
148 return QDate::fromString(Uic9183Utils::readUtf8String(m_block, m_offset, 8), QStringLiteral(
"ddMMyyyy"));
153QDate Vendor0080BLOrderBlock::validTo()
const
155 switch (m_block.version()) {
157 return QDate::fromString(Uic9183Utils::readUtf8String(m_block, m_offset + 22 + 8, 8), QStringLiteral(
"ddMMyyyy"));
159 return QDate::fromString(Uic9183Utils::readUtf8String(m_block, m_offset + 8, 8), QStringLiteral(
"ddMMyyyy"));
164QString Vendor0080BLOrderBlock::serialNumber()
const
166 switch (m_block.version()) {
168 return Uic9183Utils::readUtf8String(m_block, m_offset + 22 + 8 + 8, 8);
170 return Uic9183Utils::readUtf8String(m_block, m_offset + 8 + 8, 10);
181Vendor0080BLBlock::Vendor0080BLBlock(
const Uic9183Block &block)
187 qCWarning(Log) <<
"Unsupported version of 0080BL vendor block." << block.
version();
196bool Vendor0080BLBlock::isValid()
const
201int Vendor0080BLBlock::orderBlockCount()
const
203 return Uic9183Utils::readAsciiEncodedNumber(m_block, 2, 1);
208 if (i >= 0 && i < orderBlockCount()) {
209 switch (m_block.version()) {
225 while (!sblock.isNull()) {
226 if (strncmp(sblock.id(),
id, 3) == 0) {
229 sblock = sblock.nextBlock();
236 if (str.
size() != 3 || !isValid()) {
240 return b.isNull() ? QVariant() : QVariant::fromValue(b);
243int Vendor0080BLBlock::subblockOffset(
const Uic9183Block& block)
245 const auto certCount = *(block.
content() + 2) -
'0';
246 const auto certSize = block.
version() == 2 ? 46 : 26;
247 return 3 + certSize * certCount + 2;
251Vendor0080VUBlock::Vendor0080VUBlock(
const Uic9183Block &block)
253 if (block.
isNull() || block.
contentSize() < (
int)
sizeof(Vendor0080VUCommonData)) {
260bool Vendor0080VUBlock::isValid()
const
265const Vendor0080VUCommonData* Vendor0080VUBlock::commonData()
const
267 return m_block.isNull() ? nullptr :
reinterpret_cast<const Vendor0080VUCommonData*
>(m_block.content());
270const Vendor0080VUTicketData* Vendor0080VUBlock::ticketData(
int index)
const
272 auto offset =
sizeof(Vendor0080VUCommonData);
273 auto ticket =
reinterpret_cast<const Vendor0080VUTicketData*
>(m_block.content() + offset);
274 while (index-- > 0) {
275 offset +=
sizeof(Vendor0080VUTicketData) + ticket->validityAreaDataSize -
sizeof(VdvTicketValidityAreaData);
276 ticket =
reinterpret_cast<const Vendor0080VUTicketData*
>(m_block.content() + offset);
281#include "moc_vendor0080block.cpp"
A data block from a UIC 918.3 ticket.
int contentSize() const
Returns the size of the content data.
bool isNull() const
Checks if the block is valid or empty/default constructed.
int version() const
Returns the version number of this block.
int size() const
Returns the size of the entire block data.
const char * content() const
Returns the payload data (not including the block header).
Q_INVOKABLE KItinerary::Vendor0080BLOrderBlock orderBlock(int i) const
Order block at index i.
Vendor0080BLSubBlock firstBlock() const
First S-block, for iterating.
Vendor0080BLSubBlock findSubBlock(const char id[3]) const
Finds a S-block by type.
UIC 918.3 0080BL vendor data block order block.
UIC 918.3 0080BL vendor data block sub-block.
QString toString() const
Content as Unicode string.
const char * id() const
Type of the S-block.
Vendor0080BLSubBlock nextBlock() const
Next S-block in the 0080BL block.
int size() const
Size of the entire S-block.
int contentSize() const
Size of the content of the S-block.
Classes for reservation/travel data models, data extraction and data augmentation.
const char * constData() const const
QDate fromString(QStringView string, QStringView format, QCalendar cal)
QString fromUtf8(QByteArrayView str)
qsizetype size() const const
QByteArray toUtf8() const const