File indexing completed on 2025-01-05 05:23:51

0001 /*
0002     This file is part of the Okteta Kasten module, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2010 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef KASTEN_BYTEARRAYBASE32STREAMENCODER_HPP
0010 #define KASTEN_BYTEARRAYBASE32STREAMENCODER_HPP
0011 
0012 // lib
0013 #include "abstractbytearraystreamencoder.hpp"
0014 // Okteta core
0015 #include <Okteta/OktetaCore>
0016 // Qt
0017 #include <QString>
0018 
0019 class KConfigGroup;
0020 
0021 namespace Kasten {
0022 
0023 class Base32StreamEncoderSettings
0024 {
0025 public:
0026     enum class EncodingType
0027     {
0028         Classic = 0,
0029         Hex = 1,
0030         ZHex = 2,
0031         _Count,
0032     };
0033 
0034 private:
0035     static inline constexpr EncodingType DefaultEncodingType = EncodingType::Classic;
0036 
0037     static inline constexpr char EncodingTypeConfigKey[] = "EncodingType";
0038 
0039 public:
0040     Base32StreamEncoderSettings();
0041     Base32StreamEncoderSettings(const Base32StreamEncoderSettings&) = default;
0042 
0043     ~Base32StreamEncoderSettings() = default;
0044 
0045     Base32StreamEncoderSettings& operator=(const Base32StreamEncoderSettings&) = default;
0046 
0047     bool operator==(const Base32StreamEncoderSettings& other) const;
0048 
0049 public:
0050     void loadConfig(const KConfigGroup& configGroup);
0051     void saveConfig(KConfigGroup& configGroup) const;
0052 
0053 public:
0054     EncodingType encodingType = EncodingType::Classic;
0055 };
0056 
0057 class ByteArrayBase32StreamEncoder : public AbstractByteArrayStreamEncoder
0058 {
0059     Q_OBJECT
0060 
0061 public:
0062     enum class InputByteIndex
0063     {
0064         First = 0,
0065         Second,
0066         Third,
0067         Fourth,
0068         Fifth
0069     };
0070 
0071 private:
0072     static inline constexpr int inputGroupLength = 5;
0073 
0074     static inline constexpr int outputLineLength = 76;
0075     static inline constexpr int outputGroupLength = 8;
0076     static inline constexpr int maxOutputGroupsPerLine = outputLineLength / outputGroupLength;
0077 
0078     static inline constexpr char ConfigGroupId[] = "ByteArrayBase32StreamEncoder";
0079 
0080 public:
0081     ByteArrayBase32StreamEncoder();
0082     ~ByteArrayBase32StreamEncoder() override;
0083 
0084 public:
0085     Base32StreamEncoderSettings settings() const;
0086     void setSettings(const Base32StreamEncoderSettings& settings);
0087 
0088 protected: // AbstractByteArrayStreamEncoder API
0089     bool encodeDataToStream(QIODevice* device,
0090                             const ByteArrayView* byteArrayView,
0091                             const Okteta::AbstractByteArrayModel* byteArrayModel,
0092                             const Okteta::AddressRange& range) override;
0093 
0094 private:
0095     Base32StreamEncoderSettings mSettings;
0096 };
0097 
0098 inline Base32StreamEncoderSettings ByteArrayBase32StreamEncoder::settings() const { return mSettings; }
0099 
0100 }
0101 
0102 #endif