OpenCurves  0.9
rtbinarymessage.h
1 //
2 // author Kazys Stepanas
3 //
4 // Copyright (c) CSIRO 2015
5 //
6 #ifndef RTBINARYMESSAGE_H_
7 #define RTBINARYMESSAGE_H_
8 
9 #include "ocurvesconfig.h"
10 
11 #include "rtmessage.h"
12 
13 #include <QVariant>
14 #include <QVector>
15 
16 class QDataStream;
17 
40 class RTBinaryMessage : public RTMessage
41 {
42 public:
44  enum FieldType
45  {
50  Int8,
51  Int16,
52  Int32,
53  Int64,
54  Uint8,
55  Uint16,
56  Uint32,
57  Uint64,
58  Float32,
59  Float64
60  };
61 
63  static const unsigned TypeSizes[];
64 
67  RTBinaryMessage(bool littleEndian = false);
68 
71  inline bool littleEndian() const { return _littleEndian; }
72 
75  void setMessage(QByteArray &buffer) override;
76 
80  int readMessage(const QByteArray &buffer) override;
81 
84  QStringList headings() const override;
85 
89  unsigned populateValues(std::vector<double> &values) const override;
90 
96  void addField(const QString &name, FieldType type, bool heading = false, const QVariant &value = QVariant());
97 
101  int fieldIndex(const QString &key) const;
102 
106  double fieldValueD(const QString &key) const;
107 
112  QVariant fieldValueV(const QString &key) const;
113 
114 private:
116  struct Field
117  {
118  QString name;
119  FieldType type;
120  QVariant value;
121  bool heading;
122  };
123 
129  uint writeField(QDataStream &stream, const Field &field, uint pos);
130 
136  int readField(QDataStream &stream, Field &field, uint pos);
137 
138  QVector<Field> _fields;
139  unsigned _messageMinSize;
140  bool _littleEndian;
141  QStringList _headings;
142 };
143 
144 
145 
146 
147 #endif // RTBINARYMESSAGE_H_
static const unsigned TypeSizes[]
Sizes for various FieldType items (bytes).
Definition: rtbinarymessage.h:63
Padding. Integer value specifies how much.
Definition: rtbinarymessage.h:46
double fieldValueD(const QString &key) const
Requests a field value by name, converting to a double.
Base message handling for real time data plot communications.
Definition: rtmessage.h:29
FieldType
Fixed field types.
Definition: rtbinarymessage.h:44
QVariant fieldValueV(const QString &key) const
Requests a field value by name, returning a QVariant.
unsigned populateValues(std::vector< double > &values) const override
Request the most up to date field values.
QStringList headings() const override
Return the list of headings.
bool littleEndian() const
Does the message write little Endian?
Definition: rtbinarymessage.h:71
Represents a binary based message for real-time data plots.
Definition: rtbinarymessage.h:40
void addField(const QString &name, FieldType type, bool heading=false, const QVariant &value=QVariant())
Registers a field.
int fieldIndex(const QString &key) const
Query the index of a field named key.
int readMessage(const QByteArray &buffer) override
Read and update values from the buffer.
Pad out to the specified amount, but lookup a field for the amount.
Definition: rtbinarymessage.h:49
RTBinaryMessage(bool littleEndian=false)
Create a binary message.
Relative padding like Padding, but lookup a field for the amount.
Definition: rtbinarymessage.h:48
void setMessage(QByteArray &buffer) override
Writes the binary message to buffer.
Pad out to the specified amount.
Definition: rtbinarymessage.h:47