KItinerary

ssbticketbase.cpp
1/*
2 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "ssbticketbase.h"
8
9#include <QDebug>
10#include <QString>
11
12using namespace KItinerary;
13
14enum {
15 SSB_CHAR_WIDTH = 6,
16};
17
18SSBTicketBase::SSBTicketBase() = default;
19SSBTicketBase::~SSBTicketBase() = default;
20
21quint64 SSBTicketBase::readNumber(int start, int length) const
22{
23 if (start < 0 || length < 1 || start / 8 >= m_data.size() || (start + length) / 8 >= m_data.size() || length > 63) {
24 qWarning() << "invalid SSB read:" << start << length;
25 return {};
26 }
27
28 quint64 num = 0;
29 for (int i = 0; i < 8; ++i) {
30 num <<= 8;
31 num |= (uint8_t)*(m_data.constData() + (start / 8) + i);
32 }
33 num <<= start % 8;
34 num >>= 64 - length;
35
36 return num;
37}
38
39QString SSBTicketBase::readString(int start, int length) const
40{
41 QString res;
42 res.reserve(length);
43 for (int i = 0; i < length; ++i) {
44 auto n = readNumber(start + SSB_CHAR_WIDTH * i, SSB_CHAR_WIDTH);
45 if (n >= 36) {
46 continue;
47 }
48 if (n <= 9) {
49 res += QLatin1Char(n + '0');
50 } else {
51 res += QLatin1Char(n - 10 + 'A');
52 }
53 }
54 return res;
55}
56
57#include "moc_ssbticketbase.cpp"
Q_SCRIPTABLE Q_NOREPLY void start()
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
const char * constData() const const
qsizetype size() const const
void reserve(qsizetype size)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:49 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.