SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
simpleserializer.h
Go to the documentation of this file.
1 #ifndef INCLUDE_SIMPLESERIALIZER_H
2 #define INCLUDE_SIMPLESERIALIZER_H
3 
4 #include <QString>
5 #include <QMap>
6 #include "dsp/dsptypes.h"
7 #include "export.h"
8 
10 public:
11  SimpleSerializer(quint32 version);
12 
13  void writeS32(quint32 id, qint32 value);
14  void writeU32(quint32 id, quint32 value);
15  void writeS64(quint32 id, qint64 value);
16  void writeU64(quint32 id, quint64 value);
17  void writeFloat(quint32 id, float value);
18  void writeDouble(quint32 id, double value);
19  void writeReal(quint32 id, Real value)
20  {
21  if(sizeof(Real) == 4)
22  writeFloat(id, value);
23  else writeDouble(id, value);
24  }
25  void writeBool(quint32 id, bool value);
26  void writeString(quint32 id, const QString& value);
27  void writeBlob(quint32 id, const QByteArray& value);
28 
29  const QByteArray& final();
30 
31 protected:
32  enum Type {
33  TSigned32 = 0,
34  TUnsigned32 = 1,
35  TSigned64 = 2,
36  TUnsigned64 = 3,
37  TFloat = 4,
38  TDouble = 5,
39  TBool = 6,
40  TString = 7,
41  TBlob = 8,
42  TVersion = 9
43  };
44 
45  QByteArray m_data;
47 
48  bool writeTag(Type type, quint32 id, quint32 length);
49 };
50 
52 public:
53  SimpleDeserializer(const QByteArray& data);
54 
55  bool readS32(quint32 id, qint32* result, qint32 def = 0) const;
56  bool readU32(quint32 id, quint32* result, quint32 def = 0) const;
57  bool readS64(quint32 id, qint64* result, qint64 def = 0) const;
58  bool readU64(quint32 id, quint64* result, quint64 def = 0) const;
59  bool readFloat(quint32 id, float* result, float def = 0) const;
60  bool readDouble(quint32 id, double* result, double def = 0) const;
61  bool readReal(quint32 id, Real* result, Real def = 0) const;
62  bool readBool(quint32 id, bool* result, bool def = false) const;
63  bool readString(quint32 id, QString* result, const QString& def = QString::null) const;
64  bool readBlob(quint32 id, QByteArray* result, const QByteArray& def = QByteArray()) const;
65 
66  bool isValid() const { return m_valid; }
67  quint32 getVersion() const { return m_version; }
68  void dump() const;
69 
70 private:
71  enum Type {
72  TSigned32 = 0,
73  TUnsigned32 = 1,
74  TSigned64 = 2,
75  TUnsigned64 = 3,
76  TFloat = 4,
77  TDouble = 5,
78  TBool = 6,
79  TString = 7,
80  TBlob = 8,
81  TVersion = 9
82  };
83 
84  struct Element {
86  quint32 ofs;
87  quint32 length;
88 
89  Element(Type _type, quint32 _ofs, quint32 _length) :
90  type(_type),
91  ofs(_ofs),
92  length(_length)
93  { }
94  };
95  typedef QMap<quint32, Element> Elements;
96 
97  QByteArray m_data;
98  bool m_valid;
99  Elements m_elements;
100  quint32 m_version;
101 
102  bool parseAll();
103  bool readTag(uint* readOfs, uint readEnd, Type* type, quint32* id, quint32* length) const;
104  quint8 readByte(uint* readOfs) const
105  {
106  quint8 res = m_data[*readOfs];
107  (*readOfs)++;
108  return res;
109  }
110 };
111 
112 #endif // INCLUDE_SIMPLESERIALIZER_H
quint8 readByte(uint *readOfs) const
Element(Type _type, quint32 _ofs, quint32 _length)
bool isValid() const
quint32 getVersion() const
void writeReal(quint32 id, Real value)
#define SDRBASE_API
Definition: export.h:40
float Real
Definition: dsptypes.h:42
QMap< quint32, Element > Elements