OpenCurves  0.9
RTBinaryMessage Class Reference

Represents a binary based message for real-time data plots. More...

#include <rtbinarymessage.h>

Inheritance diagram for RTBinaryMessage:
RTMessage

Public Types

enum  FieldType {
  Padding, PadTo, PadByField, PadToField,
  Int8, Int16, Int32, Int64,
  Uint8, Uint16, Uint32, Uint64,
  Float32, Float64
}
 Fixed field types. More...
 

Public Member Functions

 RTBinaryMessage (bool littleEndian=false)
 Create a binary message. More...
 
bool littleEndian () const
 Does the message write little Endian? More...
 
void setMessage (QByteArray &buffer) override
 Writes the binary message to buffer. More...
 
int readMessage (const QByteArray &buffer) override
 Read and update values from the buffer. More...
 
QStringList headings () const override
 Return the list of headings. More...
 
unsigned populateValues (std::vector< double > &values) const override
 Request the most up to date field values. More...
 
void addField (const QString &name, FieldType type, bool heading=false, const QVariant &value=QVariant())
 Registers a field. More...
 
int fieldIndex (const QString &key) const
 Query the index of a field named key. More...
 
double fieldValueD (const QString &key) const
 Requests a field value by name, converting to a double. More...
 
QVariant fieldValueV (const QString &key) const
 Requests a field value by name, returning a QVariant. More...
 
- Public Member Functions inherited from RTMessage
virtual ~RTMessage ()
 Virtual destructor.
 

Static Public Attributes

static const unsigned TypeSizes []
 Sizes for various FieldType items (bytes).
 

Detailed Description

Represents a binary based message for real-time data plots.

This stores a number of fields and may read or write these appropriately. Each field has a known type and a default value. When writing, each field has its default value written to the buffer. When reading, each field is read from the stream, changing its value.

A field may also be a padding field. Padding may be specified

  • Padding - pad by adding a fixed byte count
  • PadTo - pad the buffer out to the specified byte count
  • PadToField - pad the buffer out to a specified byte count. The byte count is attained by reading another field. The padding field name is stored as a string in the original field's value.

The same padding process is used on reading or writing, with zero bytes used for writing padding, and padding bytes skipped while reading.

Supports writing little or big Endian.

Registered fields may be marked as headings. Only those marked as such are reported by headings() and populateValues().

Member Enumeration Documentation

Fixed field types.

Enumerator
Padding 

Padding. Integer value specifies how much.

PadTo 

Pad out to the specified amount.

PadByField 

Relative padding like Padding, but lookup a field for the amount.

PadToField 

Pad out to the specified amount, but lookup a field for the amount.

Constructor & Destructor Documentation

RTBinaryMessage::RTBinaryMessage ( bool  littleEndian = false)

Create a binary message.

Parameters
littleEndianTrue to write little Endian, false to write big.

Member Function Documentation

void RTBinaryMessage::addField ( const QString &  name,
FieldType  type,
bool  heading = false,
const QVariant &  value = QVariant() 
)

Registers a field.

Parameters
nameThe field name. May be used as a heading.
typeThe field type.
headingTrue if this field is exposed as a heading.
valueThe default or initial value.
int RTBinaryMessage::fieldIndex ( const QString &  key) const

Query the index of a field named key.

Parameters
keyThe field name to query.
Returns
The index of key or -1 if there is no such field.
double RTBinaryMessage::fieldValueD ( const QString &  key) const

Requests a field value by name, converting to a double.

Parameters
keyThe field name requested.
Returns
The field value converted to a double. Returns zero on any failure.
QVariant RTBinaryMessage::fieldValueV ( const QString &  key) const

Requests a field value by name, returning a QVariant.

Parameters
keyThe field name requested.
Returns
The field value as a QVariant. Returns a null value on any failure, but a valid field value may also be null.
QStringList RTBinaryMessage::headings ( ) const
overridevirtual

Return the list of headings.

This is the list of fields marked as headings.

Returns
The list of fields used as headings.

Implements RTMessage.

bool RTBinaryMessage::littleEndian ( ) const
inline

Does the message write little Endian?

Returns
True if writing little Endian, false if writing big.
unsigned RTBinaryMessage::populateValues ( std::vector< double > &  values) const
overridevirtual

Request the most up to date field values.

Only exposes those marked as headings.

Parameters
valuesThe values array to populate.
Returns
The number of values written.

Implements RTMessage.

int RTBinaryMessage::readMessage ( const QByteArray &  buffer)
overridevirtual

Read and update values from the buffer.

Parameters
bufferThe buffer to read from.
Returns
The number of bytes read on success, negative on error. Zero if nothing to read.

Implements RTMessage.

void RTBinaryMessage::setMessage ( QByteArray &  buffer)
overridevirtual

Writes the binary message to buffer.

Parameters
bufferThe buffer to write to.

Implements RTMessage.


The documentation for this class was generated from the following file: