AusweisApp
Lade ...
Suche ...
Keine Treffer
LengthValue.h
gehe zur Dokumentation dieser Datei
1
5#pragma once
6
7#include <QByteArray>
8#include <QtEndian>
9
10#include <algorithm>
11#include <climits>
12
13
14namespace governikus
15{
16
18{
19 private:
20 LengthValue() = delete;
21 ~LengthValue() = delete;
22
23 public:
24 template<typename T> static QByteArray readByteArray(const QByteArray& pInput, int& pOffset)
25 {
26 Q_ASSERT(sizeof(T) < INT_MAX);
27
28 const auto typeLength = static_cast<int>(sizeof(T));
29 if (pInput.size() < pOffset + typeLength)
30 {
31 return QByteArray();
32 }
33
34 const T length = qFromLittleEndian<T>(pInput.data() + pOffset);
35 pOffset += typeLength;
36 const QByteArray result = pInput.mid(pOffset, length);
37 pOffset += length;
38 return result;
39 }
40
41
42 template<typename T> static void writeByteArray(const QByteArray& pValue, QByteArray& pOutput)
43 {
44 Q_ASSERT(sizeof(T) < INT_MAX);
45
46 const int maxSize = std::numeric_limits<T>::max();
47 const int size = std::min(maxSize, static_cast<int>(pValue.size()));
48
49 const auto it = pOutput.size();
50 pOutput.resize(it + static_cast<int>(sizeof(T)));
51 qToLittleEndian(static_cast<T>(size), pOutput.data() + it);
52 pOutput += pValue.mid(0, size);
53 }
54
55
56};
57
58} // namespace governikus
Definition LengthValue.h:18
static QByteArray readByteArray(const QByteArray &pInput, int &pOffset)
Definition LengthValue.h:24
static void writeByteArray(const QByteArray &pValue, QByteArray &pOutput)
Definition LengthValue.h:42
#define T(v)
Definition http_parser.cpp:237
Defines the AccessRight and AccessRole enum.
Definition CommandApdu.h:17