File indexing completed on 2025-07-06 04:47:10
0001 /* 0002 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef KITINERARY_JSAPI_BYTEARRAY_H 0008 #define KITINERARY_JSAPI_BYTEARRAY_H 0009 0010 #include <QObject> 0011 #include <QJSValue> 0012 #include <QVariant> 0013 0014 class QByteArray; 0015 0016 namespace KItinerary { 0017 namespace JsApi { 0018 0019 /** API for dealing with QByteArray and/or JS ArrayBuffer objects. */ 0020 class ByteArray : public QObject 0021 { 0022 Q_OBJECT 0023 public: 0024 /** Perform zlib decompression on the given byte array. 0025 * @returns a JS ArrayBuffer with the decompressed result. 0026 */ 0027 Q_INVOKABLE QJSValue inflate(const QByteArray &input) const; 0028 0029 /** Converts the given QByteArray or JS ArrayBuffer into an base64 encoded string. */ 0030 Q_INVOKABLE QString toBase64(const QByteArray &input) const; 0031 /** Converts a given Base64 encoded string to a JS ArrayBuffer. */ 0032 Q_INVOKABLE QJSValue fromBase64(const QString &b64) const; 0033 0034 /** Convert a QByteArray/ArrayBuffer to a string, assuming UTF-8 encoding. */ 0035 Q_INVOKABLE QString decodeUtf8(const QByteArray &input) const; 0036 /** Convert a QByteArray/ArrayBuffer to a string, assuming Latin1 encoding. */ 0037 Q_INVOKABLE QString decodeLatin1(const QByteArray &input) const; 0038 0039 /** Converts the given QByteArray or JS ArrayBuffer into a BitArray. */ 0040 Q_INVOKABLE QVariant toBitArray(const QByteArray &input) const; 0041 0042 /** Creates a Protocol Buffers stream reader for the given JS ArrayBuffer. */ 0043 Q_INVOKABLE QVariant toProtobufStreamReader(const QByteArray &input) const; 0044 0045 /** Decode/decrypt a UK RSP-6 ticket barcode. */ 0046 Q_INVOKABLE QJSValue decodeRsp6Ticket(const QString &text) const; 0047 0048 /** Convert a QByteArray to a JS ArrayBuffer. 0049 * This is mainly a migration aid until we return ArrayBuffers everywhere. 0050 */ 0051 Q_INVOKABLE QJSValue toArrayBuffer(const QByteArray &input) const; 0052 }; 0053 0054 }} 0055 0056 #endif // KITINERARY_JSAPI_BYTEARRAY_H