OSC-like binary data storage. More...
#include <Radiant/BinaryData.hpp>
Public Member Functions | |
| void | append (const BinaryData &that) |
| Appends another BinaryData object to this. More... | |
| BinaryData () | |
| Constructs empty data container. | |
| BinaryData (const BinaryData &) | |
| Copy constructor. | |
| void | clear () |
| Rewind the buffer and fill it with zeroes. | |
| char * | data () |
| Returns a pointer to the buffer. More... | |
| const char * | data () const |
| Returns a pointer to the buffer. More... | |
| void | ensure (size_t bytes) |
| Ensure that at least required amount of bytes is available. More... | |
| void | linkTo (void *data, int capacity) |
| Makes the buffer point to existing memory. More... | |
| bool | loadFromFile (const char *filename, size_t maxSize=10000000) |
| Reads data from a file. More... | |
| BinaryData & | operator= (const BinaryData &that) |
| Copy a buffer object. More... | |
| int32_t | peekMarker (bool *ok=0) const |
| Extracts the next marker code from the stream. More... | |
| int | pos () const |
| Tells the current position of the read/write pointer. More... | |
| template<class T > | |
| T | read (bool *ok=0) |
| Read a value from the data. More... | |
| bool | read (Radiant::BinaryStream &stream, int timeoutMs=-1) |
| Reads the buffer from a stream. More... | |
| template<> | |
| float | read (bool *ok) |
| template<> | |
| double | read (bool *ok) |
| template<> | |
| int | read (bool *ok) |
| template<> | |
| unsigned int | read (bool *ok) |
| template<> | |
| bool | read (bool *ok) |
| template<> | |
| int64_t | read (bool *ok) |
| template<> | |
| TimeStamp | read (bool *ok) |
| template<> | |
| uint64_t | read (bool *ok) |
| template<> | |
| Nimble::Vector2f | read (bool *ok) |
| template<> | |
| Nimble::Vector3f | read (bool *ok) |
| template<> | |
| Nimble::Vector4f | read (bool *ok) |
| template<> | |
| Nimble::Frame4f | read (bool *ok) |
| template<> | |
| Nimble::Vector2i | read (bool *ok) |
| template<> | |
| Nimble::Vector3i | read (bool *ok) |
| template<> | |
| Nimble::Vector4i | read (bool *ok) |
| template<> | |
| Color | read (bool *ok) |
| template<> | |
| QString | read (bool *ok) |
| template<> | |
| QByteArray | read (bool *ok) |
| bool | readBlob (void *ptr, int n) |
| Reads a blob of expected size. More... | |
| bool | readBlob (std::vector< uint8_t > &buf) |
| Reads a blob of expected size. More... | |
| float | readFloat32 (bool *ok=0) |
| Read a value from the buffer Tries to read the matching value type from the buffer. More... | |
| double | readFloat64 (bool *ok=0) |
| Read a value from the buffer Tries to read the matching value type from the buffer. More... | |
| int32_t | readInt32 (bool *ok=0) |
| Read a value from the buffer Tries to read the matching value type from the buffer. More... | |
| int64_t | readInt64 (bool *ok=0) |
| Read a value from the buffer Tries to read the matching value type from the buffer. More... | |
| bool | readString (char *str, size_t maxbytes) |
| Read a null-terminated string from the buffer. More... | |
| bool | readString (QString &str) |
| Read a string from the buffer. More... | |
| bool | readString (QByteArray &str) |
| Read a string from the buffer. More... | |
| TimeStamp | readTimeStamp (bool *ok=0) |
| Read a value from the buffer Tries to read the matching value type from the buffer. More... | |
| Nimble::Vector2f | readVector2Float32 (bool *ok=0) |
| Reads a 2D 32-bit floating point vector from the buffer. More... | |
| Nimble::Vector2i | readVector2Int32 (bool *ok=0) |
| Reads a 2D 32-bit integer vector from the buffer. More... | |
| Nimble::Vector3f | readVector3Float32 (bool *ok=0) |
| Reads a 3D 32-bit floating point vector from the buffer. More... | |
| Nimble::Vector3i | readVector3Int32 (bool *ok=0) |
| Reads a 3D 32-bit integer vector from the buffer. More... | |
| Nimble::Vector4f | readVector4Float32 (bool *ok=0) |
| Reads a 4D 32-bit float vector from the buffer. More... | |
| Nimble::Vector4i | readVector4Int32 (bool *ok=0) |
| Reads a 4D 32-bit integer vector from the buffer. More... | |
| void | rewind () |
| Rewind the index pointer to the beginning. | |
| bool | saveToFile (const char *filename) const |
| Saves this buffer to the given file. More... | |
| void | setPos (int index) |
| Sets the position of the read/write pointer. More... | |
| void | setTotal (unsigned bytes) |
| Sets the total number of bytes used by this buffer. More... | |
| int | total () const |
| Returns the total number of bytes used by this buffer. More... | |
| void | write (float v) |
| Writes a 32-bit floating point number to the data buffer. More... | |
| void | write (double v) |
| Writes a 32-bit floating point number to the data buffer. More... | |
| void | write (bool v) |
| Writes a bool to the data buffer. More... | |
| void | write (int32_t v) |
| Writes a 32-bit integer to the data buffer. More... | |
| void | write (int64_t v) |
| Writes a 64-bit integer to the data buffer. More... | |
| void | write (const Radiant::TimeStamp &ts) |
| Write a 64-bit time-stamp to the data buffer The timestamp uses Radiant::TimeStamp internal structure (40+24 bit fixed-point value). More... | |
| void | write (const char *str) |
| Write a null-terminated string to the buffer. More... | |
| void | write (const QString &str) |
| Write a string to the buffer. More... | |
| void | write (const QByteArray &str) |
| Write a string to the buffer. More... | |
| void | write (Nimble::Vector2f v) |
| Writes a 2D 32-bit floating point vector to the data buffer. More... | |
| void | write (Nimble::Vector3f v) |
| Writes a 3D 32-bit floating point vector to the data buffer. More... | |
| void | write (Nimble::Vector2i v) |
| Writes a 2D 32-bit integer vector to the data buffer. More... | |
| void | write (Nimble::Vector3i v) |
| Writes a 3D 32-bit integer vector to the data buffer. More... | |
| void | write (const Nimble::Vector4i &v) |
| Writes a 4D 32-bit integer vector to the data buffer. More... | |
| void | write (const Nimble::Vector4f &v) |
| Writes a 4D 32-bit float vector to the data buffer. More... | |
| bool | write (Radiant::BinaryStream &stream) const |
| Writes the buffer into a stream. More... | |
| void | writeBlob (const void *ptr, int n) |
| Writes binary blob to the buffer. More... | |
| void | writeFloat32 (float v) |
| Writes a 32-bit floating point number to the data buffer. More... | |
| void | writeFloat64 (double v) |
| Writes a 32-bit floating point number to the data buffer. More... | |
| void | writeInt32 (int32_t v) |
| Writes a 32-bit integer to the data buffer. More... | |
| void | writeInt64 (int64_t v) |
| Writes a 64-bit integer to the data buffer. More... | |
| void | writePointer (void *ptr) |
| Writes a 64-bit integer to the data buffer. More... | |
| void | writeString (const char *str) |
| Write a null-terminated string to the buffer. More... | |
| void | writeString (const QString &str) |
| Write a string to the buffer. More... | |
| void | writeString (const QByteArray &str) |
| Write a string to the buffer. More... | |
| void | writeTimeStamp (TimeStamp v) |
| Write a 64-bit time-stamp to the data buffer The timestamp uses Radiant::TimeStamp internal structure (40+24 bit fixed-point value). More... | |
| void | writeVector2Float32 (Nimble::Vector2f v) |
| Writes a 2D 32-bit floating point vector to the data buffer. More... | |
| void | writeVector2Int32 (Nimble::Vector2i v) |
| Writes a 2D 32-bit integer vector to the data buffer. More... | |
| void | writeVector3Float32 (Nimble::Vector3f v) |
| Writes a 3D 32-bit floating point vector to the data buffer. More... | |
| void | writeVector3Int32 (Nimble::Vector3i v) |
| Writes a 3D 32-bit integer vector to the data buffer. More... | |
| void | writeVector4Float32 (const Nimble::Vector4f &v) |
| Writes a 4D 32-bit float vector to the data buffer. More... | |
| void | writeVector4Int32 (const Nimble::Vector4i &v) |
| Writes a 4D 32-bit integer vector to the data buffer. More... | |
| ~BinaryData () | |
| Destructor. | |
OSC-like binary data storage.
This class encapsulates control messages in a binary buffer. The data is stored in pretty much the same way as in Open Sound Control (OSC). This is done to ensure easy control data conversion between Radiant and OSC-compliant applications.
Differences between Radiant and OSC:
In ControlData the byte order is machine native byte order, for performance reasons.
Time-stamp for is slightly different. In Radiant the the timestamps are 40+24 bits fixed point while in OSC they are 32+32 bit fixed point.
In Radiant, there is no address matching
In Radiant, the type of each parameter is stored right before the parameter, to make writing/reading the stream easier.
In Radiant strings are padded to 4-byte margin (like OSC), but the padding does not need to be zeros.
OSC basic types are well known, so automatic conversion of all the differences should be easy enough.
Wrting functions always put the type marker before the actual value.
Reading functions set the optional bool argument "ok" to true if the operation is successful and to false if it fails.
| void Radiant::BinaryData::append | ( | const BinaryData & | that | ) |
Appends another BinaryData object to this.
| that | BinaryData to append |
|
inline |
Returns a pointer to the buffer.
|
inline |
Returns a pointer to the buffer.
| void Radiant::BinaryData::ensure | ( | size_t | bytes | ) |
Ensure that at least required amount of bytes is available.
| bytes |
| void Radiant::BinaryData::linkTo | ( | void * | data, |
| int | capacity | ||
| ) |
Makes the buffer point to existing memory.
The shared memory will not be freed when the BinaryData object is destroyed.
| data | Pointer to data that is being shared |
| capacity | Size of the BinaryData |
| bool Radiant::BinaryData::loadFromFile | ( | const char * | filename, |
| size_t | maxSize = 10000000 |
||
| ) |
Reads data from a file.
| filename | Name of the file where data is loaded |
| maxSize | Maximum size of the read in bytes |
|
inline |
Copy a buffer object.
| that | Buffer to assign |
| int32_t Radiant::BinaryData::peekMarker | ( | bool * | ok = 0 | ) | const |
Extracts the next marker code from the stream.
| [out] | ok | check if the read was successful |
|
inline |
Tells the current position of the read/write pointer.
|
inline |
Read a value from the data.
| [out] | ok | If read was succesful true is writtten to this, otherwise false. |
| T | Type of value to read |
| bool Radiant::BinaryData::read | ( | Radiant::BinaryStream & | stream, |
| int | timeoutMs = -1 |
||
| ) |
Reads the buffer from a stream.
| stream | Stream to read from |
| timeoutMs | How many milliseconds the data is waited for. -1 if waiting indefinitively. |
| bool Radiant::BinaryData::readBlob | ( | void * | ptr, |
| int | n | ||
| ) |
Reads a blob of expected size.
| [out] | ptr | buffer to write to |
| n | bytes to read |
| bool Radiant::BinaryData::readBlob | ( | std::vector< uint8_t > & | buf | ) |
Reads a blob of expected size.
| [out] | buf | buffer to write to. The buffer will be resized to fit the data |
| float Radiant::BinaryData::readFloat32 | ( | bool * | ok = 0 | ) |
Read a value from the buffer Tries to read the matching value type from the buffer.
If successful the value is returned and the buffer read position is incremented. If the read fails, zero is returned and the optional ok flag is set to false.
| [out] | ok | check if the read was successful |
| double Radiant::BinaryData::readFloat64 | ( | bool * | ok = 0 | ) |
Read a value from the buffer Tries to read the matching value type from the buffer.
If successful the value is returned and the buffer read position is incremented. If the read fails, zero is returned and the optional ok flag is set to false.
| [out] | ok | check if the read was successful |
| int32_t Radiant::BinaryData::readInt32 | ( | bool * | ok = 0 | ) |
Read a value from the buffer Tries to read the matching value type from the buffer.
If successful the value is returned and the buffer read position is incremented. If the read fails, zero is returned and the optional ok flag is set to false.
| [out] | ok | check if the read was successful |
| int64_t Radiant::BinaryData::readInt64 | ( | bool * | ok = 0 | ) |
Read a value from the buffer Tries to read the matching value type from the buffer.
If successful the value is returned and the buffer read position is incremented. If the read fails, zero is returned and the optional ok flag is set to false.
| [out] | ok | check if the read was successful |
| bool Radiant::BinaryData::readString | ( | char * | str, |
| size_t | maxbytes | ||
| ) |
Read a null-terminated string from the buffer.
| [out] | str | string buffer to write to |
| maxbytes | maximum number of bytes to read |
| bool Radiant::BinaryData::readString | ( | QString & | str | ) |
Read a string from the buffer.
| [out] | str | string to write to |
| bool Radiant::BinaryData::readString | ( | QByteArray & | str | ) |
Read a string from the buffer.
| [out] | str | string to write to |
| TimeStamp Radiant::BinaryData::readTimeStamp | ( | bool * | ok = 0 | ) |
Read a value from the buffer Tries to read the matching value type from the buffer.
If successful the value is returned and the buffer read position is incremented. If the read fails, zero is returned and the optional ok flag is set to false.
| [out] | ok | check if the read was successful |
| Nimble::Vector2f Radiant::BinaryData::readVector2Float32 | ( | bool * | ok = 0 | ) |
Reads a 2D 32-bit floating point vector from the buffer.
| [out] | ok | check if the read was successful |
| Nimble::Vector2i Radiant::BinaryData::readVector2Int32 | ( | bool * | ok = 0 | ) |
Reads a 2D 32-bit integer vector from the buffer.
| [out] | ok | check if the read was successful |
| Nimble::Vector3f Radiant::BinaryData::readVector3Float32 | ( | bool * | ok = 0 | ) |
Reads a 3D 32-bit floating point vector from the buffer.
| [out] | ok | check if the read was successful |
| Nimble::Vector3i Radiant::BinaryData::readVector3Int32 | ( | bool * | ok = 0 | ) |
Reads a 3D 32-bit integer vector from the buffer.
| [out] | ok | check if the read was successful |
| Nimble::Vector4f Radiant::BinaryData::readVector4Float32 | ( | bool * | ok = 0 | ) |
Reads a 4D 32-bit float vector from the buffer.
| [out] | ok | check if the read was successful |
| Nimble::Vector4i Radiant::BinaryData::readVector4Int32 | ( | bool * | ok = 0 | ) |
Reads a 4D 32-bit integer vector from the buffer.
| [out] | ok | check if the read was successful |
| bool Radiant::BinaryData::saveToFile | ( | const char * | filename | ) | const |
Saves this buffer to the given file.
| filename | Name of the target file |
|
inline |
Sets the position of the read/write pointer.
| index | Bytes from the beginning |
|
inline |
Sets the total number of bytes used by this buffer.
| bytes | Use at most this many bytes |
|
inline |
Returns the total number of bytes used by this buffer.
|
inline |
Writes a 32-bit floating point number to the data buffer.
| v | Value to write |
|
inline |
Writes a 32-bit floating point number to the data buffer.
| v | Value to write |
|
inline |
Writes a bool to the data buffer.
| v | Value to write |
|
inline |
Writes a 32-bit integer to the data buffer.
| v | Value to write |
|
inline |
Writes a 64-bit integer to the data buffer.
| v | Value to write |
|
inline |
Write a 64-bit time-stamp to the data buffer The timestamp uses Radiant::TimeStamp internal structure (40+24 bit fixed-point value).
| ts | time-stamp to write |
|
inline |
Write a null-terminated string to the buffer.
| str | String to write |
|
inline |
Write a string to the buffer.
| str | string to write |
|
inline |
Write a string to the buffer.
| str | string to write |
|
inline |
Writes a 2D 32-bit floating point vector to the data buffer.
| v | Value to write |
|
inline |
Writes a 3D 32-bit floating point vector to the data buffer.
| v | Value to write |
|
inline |
Writes a 2D 32-bit integer vector to the data buffer.
| v | Value to write |
|
inline |
Writes a 3D 32-bit integer vector to the data buffer.
| v | Value to write |
|
inline |
Writes a 4D 32-bit integer vector to the data buffer.
| v | Value to write |
|
inline |
Writes a 4D 32-bit float vector to the data buffer.
| v | Value to write |
| bool Radiant::BinaryData::write | ( | Radiant::BinaryStream & | stream | ) | const |
Writes the buffer into a stream.
| stream | Stream to write |
| void Radiant::BinaryData::writeBlob | ( | const void * | ptr, |
| int | n | ||
| ) |
Writes binary blob to the buffer.
| ptr | Pointer to blob |
| n | Bytes to write |
| void Radiant::BinaryData::writeFloat32 | ( | float | v | ) |
Writes a 32-bit floating point number to the data buffer.
| v | Value to write |
| void Radiant::BinaryData::writeFloat64 | ( | double | v | ) |
Writes a 32-bit floating point number to the data buffer.
| v | Value to write |
| void Radiant::BinaryData::writeInt32 | ( | int32_t | v | ) |
Writes a 32-bit integer to the data buffer.
| v | Value to write |
| void Radiant::BinaryData::writeInt64 | ( | int64_t | v | ) |
Writes a 64-bit integer to the data buffer.
| v | Value to write |
|
inline |
Writes a 64-bit integer to the data buffer.
| ptr | Value to write |
| void Radiant::BinaryData::writeString | ( | const char * | str | ) |
Write a null-terminated string to the buffer.
| str | String to write |
|
inline |
Write a string to the buffer.
| str | string to write |
|
inline |
Write a string to the buffer.
| str | string to write |
| void Radiant::BinaryData::writeTimeStamp | ( | TimeStamp | v | ) |
Write a 64-bit time-stamp to the data buffer The timestamp uses Radiant::TimeStamp internal structure (40+24 bit fixed-point value).
| v | time-stamp to write |
| void Radiant::BinaryData::writeVector2Float32 | ( | Nimble::Vector2f | v | ) |
Writes a 2D 32-bit floating point vector to the data buffer.
| v | Value to write |
| void Radiant::BinaryData::writeVector2Int32 | ( | Nimble::Vector2i | v | ) |
Writes a 2D 32-bit integer vector to the data buffer.
| v | Value to write |
| void Radiant::BinaryData::writeVector3Float32 | ( | Nimble::Vector3f | v | ) |
Writes a 3D 32-bit floating point vector to the data buffer.
| v | Value to write |
| void Radiant::BinaryData::writeVector3Int32 | ( | Nimble::Vector3i | v | ) |
Writes a 3D 32-bit integer vector to the data buffer.
| v | Value to write |
| void Radiant::BinaryData::writeVector4Float32 | ( | const Nimble::Vector4f & | v | ) |
Writes a 4D 32-bit float vector to the data buffer.
| v | Value to write |
| void Radiant::BinaryData::writeVector4Int32 | ( | const Nimble::Vector4i & | v | ) |
Writes a 4D 32-bit integer vector to the data buffer.
| v | Value to write |