karoo::rock_data Class Reference

This class is used for serialising data to/from an array of bytes. More...

#include <data.h>

Inheritance diagram for karoo::rock_data:

karoo::rock_datagram_message

List of all members.

Public Member Functions

 rock_data ()
 Construct a rock_data object.
virtual void accomodate (size_t bytes)=0
 Attempt to resize the buffer so that it can fit more bytes after its current size value.
virtual void write (const void *data, size_t size)=0
 Write data bytes to the array.
virtual void read (void *data, size_t size)=0
 Read data bytes from the array.
void writeNumber (const void *data, size_t size)
 This calls write() directly if the byte order is little_endian, else it calls write() for each byte, in reverse order.
void readNumber (void *data, size_t size)
 This calls read() directly if the byte order is little_endian, else it calls read() for each byte, in reverse order.
void writeU8 (const uint8_t &data)
 This calls writeNumber(), passing the correct data size = 1.
void writeU16 (const uint16_t &data)
 This calls writeNumber(), passing the correct data size = 2.
void writeU32 (const uint32_t &data)
 This calls writeNumber(), passing the correct data size = 4.
void writeU64 (const uint64_t &data)
 This calls writeNumber(), passing the correct data size = 8.
void writeI8 (const int8_t &data)
 This calls writeNumber(), passing the correct data size = 1.
void writeI16 (const int16_t &data)
 This calls writeNumber(), passing the correct data size = 2.
void writeI32 (const int32_t &data)
 This calls writeNumber(), passing the correct data size = 4.
void writeI64 (const int64_t &data)
 This calls writeNumber(), passing the correct data size = 8.
void writeF (const float &data)
 This calls writeNumber(), passing the correct data size = 4.
void writeD (const double &data)
 This calls writeNumber(), passing the correct data size = 8.
void writeLD (const long double &data)
 This writes the fraction first as 8 bytes little_endian, then writes the exponent as 4 bytes little_endian.
void readU8 (uint8_t &data)
 This calls readNumber(), passing the correct data size = 1.
void readU16 (uint16_t &data)
 This calls readNumber(), passing the correct data size = 2.
void readU32 (uint32_t &data)
 This calls readNumber(), passing the correct data size = 4.
void readU64 (uint64_t &data)
 This calls readNumber(), passing the correct data size = 8.
void readI8 (int8_t &data)
 This calls readNumber(), passing the correct data size = 1.
void readI16 (int16_t &data)
 This calls readNumber(), passing the correct data size = 2.
void readI32 (int32_t &data)
 This calls readNumber(), passing the correct data size = 4.
void readI64 (int64_t &data)
 This calls readNumber(), passing the correct data size = 8.
void readF (float &data)
 This calls readNumber(), passing the correct data size = 4.
void readD (double &data)
 This calls readNumber(), passing the correct data size = 8.
void readLD (long double &data)
 Reads the 8 bytes fractional part and the 4 byte exponent, and converts to a long double.
void writeS (const text &str)
 Writes the string length as 4 a byte unsigned integer, then writes the characters that form the string.
void readS (text &str)
 Reads the 4 byte string length, then reads that many bytes and forms a character string.


Detailed Description

This class is used for serialising data to/from an array of bytes.

Its used really just to get data into a datagram, or to read it from a datagram. The format is Little Endian. Long Double format is also supported, using a 64 bit fractional part and 32 bit exponent.

This class has two pure virtuals which you must be implemented

See also:
rock_datagram_message.

Constructor & Destructor Documentation

karoo::rock_data::rock_data (  )  [inline]

Construct a rock_data object.

This class has pure virtuals, and no storage data, so the constructor does nothing.


Member Function Documentation

virtual void karoo::rock_data::accomodate ( size_t  bytes  )  [pure virtual]

Attempt to resize the buffer so that it can fit more bytes after its current size value.

Note that if the buffer is already large enough, nothing will happen.

Parameters:
bytes the number of extra bytes to resize the buffer to
Exceptions:
bad_alloc if the buffer could not be resized

Implemented in karoo::rock_datagram_message.

virtual void karoo::rock_data::read ( void *  data,
size_t  size 
) [pure virtual]

Read data bytes from the array.

Parameters:
data the data bytes to read.
size the number of bytes of data.
Exceptions:
rock_exception_read if there was an array bounds error.

Implemented in karoo::rock_datagram_message.

void karoo::rock_data::readD ( double &  data  )  [inline]

This calls readNumber(), passing the correct data size = 8.

Parameters:
data the 64 bit double floating point real number to read
Exceptions:
rock_exception_read may be thrown by read()

References readNumber().

void karoo::rock_data::readF ( float &  data  )  [inline]

This calls readNumber(), passing the correct data size = 4.

Parameters:
data the 32 bit floating point real number to read
Exceptions:
rock_exception_read may be thrown by read()

References readNumber().

void karoo::rock_data::readI16 ( int16_t &  data  )  [inline]

This calls readNumber(), passing the correct data size = 2.

Parameters:
data the signed 16 bit short integer to read
Exceptions:
rock_exception_read may be thrown by read()

References readNumber().

void karoo::rock_data::readI32 ( int32_t &  data  )  [inline]

This calls readNumber(), passing the correct data size = 4.

Parameters:
data the signed 32 bit integer to read
Exceptions:
rock_exception_read may be thrown by read()

References readNumber().

void karoo::rock_data::readI64 ( int64_t &  data  )  [inline]

This calls readNumber(), passing the correct data size = 8.

Parameters:
data the signed 64 bit integer to read
Exceptions:
rock_exception_read may be thrown by read()

References readNumber().

void karoo::rock_data::readI8 ( int8_t &  data  )  [inline]

This calls readNumber(), passing the correct data size = 1.

Parameters:
data the signed byte to read
Exceptions:
rock_exception_read may be thrown by read()

References readNumber().

void karoo::rock_data::readLD ( long double &  data  ) 

Reads the 8 bytes fractional part and the 4 byte exponent, and converts to a long double.

Parameters:
data the 96 bit long double floating point real number to read
Exceptions:
rock_exception_read may be thrown by read()

void karoo::rock_data::readNumber ( void *  data,
size_t  size 
)

This calls read() directly if the byte order is little_endian, else it calls read() for each byte, in reverse order.

Parameters:
data the data bytes to read
size the number of bytes of data.
Exceptions:
rock_exception_read may be thrown by read()

Referenced by readD(), readF(), readI16(), readI32(), readI64(), readI8(), readU16(), readU32(), readU64(), and readU8().

void karoo::rock_data::readS ( text str  ) 

Reads the 4 byte string length, then reads that many bytes and forms a character string.

Parameters:
str the string to read.
Exceptions:
rock_exception_read may be thrown by read()

void karoo::rock_data::readU16 ( uint16_t &  data  )  [inline]

This calls readNumber(), passing the correct data size = 2.

Parameters:
data the unsigned 16 bit integer to read
Exceptions:
rock_exception_read may be thrown by read()

References readNumber().

void karoo::rock_data::readU32 ( uint32_t &  data  )  [inline]

This calls readNumber(), passing the correct data size = 4.

Parameters:
data the unsigned 32 bit integer to read
Exceptions:
rock_exception_read may be thrown by read()

References readNumber().

void karoo::rock_data::readU64 ( uint64_t &  data  )  [inline]

This calls readNumber(), passing the correct data size = 8.

Parameters:
data the unsigned 64 bit integer to read
Exceptions:
rock_exception_read may be thrown by read()

References readNumber().

void karoo::rock_data::readU8 ( uint8_t &  data  )  [inline]

This calls readNumber(), passing the correct data size = 1.

Parameters:
data the unsigned byte to read
Exceptions:
rock_exception_read may be thrown by read()

References readNumber().

virtual void karoo::rock_data::write ( const void *  data,
size_t  size 
) [pure virtual]

Write data bytes to the array.

Parameters:
data the data bytes to write.
size the number of bytes of data.
Exceptions:
bad_alloc if the buffer could not be resized

Implemented in karoo::rock_datagram_message.

void karoo::rock_data::writeD ( const double &  data  )  [inline]

This calls writeNumber(), passing the correct data size = 8.

Parameters:
data the 64 bit double floating point real number to write
Exceptions:
bad_alloc may be thrown by write()

References writeNumber().

void karoo::rock_data::writeF ( const float &  data  )  [inline]

This calls writeNumber(), passing the correct data size = 4.

Parameters:
data the 32 bit floating point real number to write
Exceptions:
bad_alloc may be thrown by write()

References writeNumber().

void karoo::rock_data::writeI16 ( const int16_t &  data  )  [inline]

This calls writeNumber(), passing the correct data size = 2.

Parameters:
data the signed 16 bit short integer to write
Exceptions:
bad_alloc may be thrown by write()

References writeNumber().

void karoo::rock_data::writeI32 ( const int32_t &  data  )  [inline]

This calls writeNumber(), passing the correct data size = 4.

Parameters:
data the signed 32 bit integer to write
Exceptions:
bad_alloc may be thrown by write()

References writeNumber().

void karoo::rock_data::writeI64 ( const int64_t &  data  )  [inline]

This calls writeNumber(), passing the correct data size = 8.

Parameters:
data the signed 64 bit long integer to write
Exceptions:
bad_alloc may be thrown by write()

References writeNumber().

void karoo::rock_data::writeI8 ( const int8_t &  data  )  [inline]

This calls writeNumber(), passing the correct data size = 1.

Parameters:
data the signed byte to write
Exceptions:
bad_alloc may be thrown by write()

References writeNumber().

void karoo::rock_data::writeLD ( const long double &  data  ) 

This writes the fraction first as 8 bytes little_endian, then writes the exponent as 4 bytes little_endian.

The fraction is written as a 64 bit signed integer, and the exponent is a 32 bit signed integer. To convert back to a long double, frac * (((UINT64_MAX)>>1)-1) * 2^exp.

Parameters:
data the 96 bit long double floating point real number to write
Exceptions:
bad_alloc may be thrown by write()

void karoo::rock_data::writeNumber ( const void *  data,
size_t  size 
)

This calls write() directly if the byte order is little_endian, else it calls write() for each byte, in reverse order.

Parameters:
data the data bytes to write
size the number of bytes of data.
Exceptions:
bad_alloc may be thrown by write()

Referenced by writeD(), writeF(), writeI16(), writeI32(), writeI64(), writeI8(), writeU16(), writeU32(), writeU64(), and writeU8().

void karoo::rock_data::writeS ( const text str  ) 

Writes the string length as 4 a byte unsigned integer, then writes the characters that form the string.

Parameters:
str the string to write.
Exceptions:
bad_alloc may be thrown by write()

void karoo::rock_data::writeU16 ( const uint16_t &  data  )  [inline]

This calls writeNumber(), passing the correct data size = 2.

Parameters:
data the unsigned 16 bit short integer to write
Exceptions:
bad_alloc may be thrown by write()

References writeNumber().

void karoo::rock_data::writeU32 ( const uint32_t &  data  )  [inline]

This calls writeNumber(), passing the correct data size = 4.

Parameters:
data the unsigned 32 bit integer to write
Exceptions:
bad_alloc may be thrown by write()

References writeNumber().

void karoo::rock_data::writeU64 ( const uint64_t &  data  )  [inline]

This calls writeNumber(), passing the correct data size = 8.

Parameters:
data the unsigned 64 bit long integer to write
Exceptions:
bad_alloc may be thrown by write()

References writeNumber().

void karoo::rock_data::writeU8 ( const uint8_t &  data  )  [inline]

This calls writeNumber(), passing the correct data size = 1.

Parameters:
data the unsigned byte to write
Exceptions:
bad_alloc may be thrown by write()

References writeNumber().


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

Generated on Tue Feb 16 15:04:29 2010 for Karoo by  doxygen 1.5.8