message_t Class Reference

Class representing a data to send or receive using network_t. More...

#include <message.hh>

List of all members.

Public Member Functions

void append_bool (const bool flag)
 Writes a flag to the message.
void append_byte (const byte_t number)
 Writes a number of type byte_t to the message.
void append_data (const byte_t *const data_to_copy, const size_int_t size_to_copy)
 Writes `size_to_copy' bytes from `data_to_copy' to the message.
void append_sbyte (const sbyte_t number)
 Writes a number of type sbyte_t to the message.
void append_size_int (const size_int_t number)
 Writes a number of type size_int_t to the message.
void append_slong_int (const slong_int_t number)
 Writes a number of type slong_int_t to the message.
void append_sshort_int (const sshort_int_t number)
 Writes a number of type sshort_int_t to the message.
void append_state (const state_t state)
 Writes a complete representation of state to the message.
void append_state_ref (const state_ref_t state_ref)
 Writes a state reference `state_ref' to the message.
void append_ulong_int (const ulong_int_t number)
 Writes a number of type ulong_int_t to the message.
void append_ushort_int (const ushort_int_t number)
 Writes a number of type ushort_int_t to the message.
size_int_t get_allocated_size () const
 Returns a size of byte sequence representing a message.
const byte_t * get_data () const
 Returns a stored byte sequence representing a message.
byte_t * get_data ()
 Returns a stored byte sequence representing a message.
size_int_t get_written_size () const
void load_data (byte_t *const new_data, const size_int_t new_allocated_size)
 Replaces a data in a message by given data (using memory copying).
 message_t (const size_int_t number_of_preallocated_bytes=1024, const size_int_t reallocation_step=1024)
 A constructor.
void read_bool (bool &flag)
 Copies a flag from the message to `flag'.
void read_byte (byte_t &number)
 Copies a number of type byte_t to `number'.
void read_data (char *const data_to_copy, const std::size_t size_to_copy)
 Copies `size_to_copy' bytes from the message to `data_to_copy'.
void read_sbyte (sbyte_t &number)
 Copies a number of type sbyte_t to `number'.
void read_size_int (size_int_t &number)
 Copies a number of type size_int_t to `number'.
void read_slong_int (slong_int_t &number)
 Copies a number of type slong_int_t to `number'.
void read_sshort_int (sshort_int_t &number)
 Copies a number of type sshort_int_t to `number'.
void read_state (state_t &state)
 Copies a state stored in the message to `state'.
void read_state_ref (state_ref_t &ref)
 Copies a reference to state stored in the message to `ref'.
void read_ulong_int (ulong_int_t &number)
 Copies a number of type ulong_int_t to `number'.
void read_ushort_int (ushort_int_t &number)
 Copies a number of type ushort_int_t to `number'.
void rewind ()
 Moves both reading and writting heads to the beginning of the message.
void rewind_append ()
 Moves a writting head to the beginning of the message.
void rewind_read ()
 Moves a reading head to the beginning of the message.
void set_data (byte_t *const new_data, const size_int_t new_allocated_size)
 Sets a byte sequence stored in a message.
void set_data (byte_t *const new_data, const size_int_t new_allocated_size, const size_int_t new_written_size)
 Sets a byte sequence stored in a message.
void set_written_size (const size_int_t new_size)
 Sets a size of written part of message.
 ~message_t ()
 A destructor.


Detailed Description

Class representing a data to send or receive using network_t.

This class is good for sending or receiving of messages consisting of several items (of possibly various types). It supports a transmission of basic integer types, states, state references and general sequences of bytes.

Warning:
This class implicitly allocates 4096 B. It is not good idea to have 1000000 instances of it or to create and destroy its instances many times. It is presumed, that in a program there will be only few "global" instances shared by all sending and receiving procedures.

Constructor & Destructor Documentation

message_t ( const size_int_t  number_of_preallocated_bytes = 1024,
const size_int_t  reallocation_step = 1024 
)

A constructor.

Parameters:
number_of_preallocated_bytes = a count of bytes to allocate for a byte sequence representing a message
reallocation_step = how much more bytes to allocate in case of reallocation

~message_t (  )  [inline]

A destructor.

It only deallocates a byte sequence stored in a message


Member Function Documentation

void append_bool ( const bool  flag  ) 

Writes a flag to the message.

Warning:
Flag is stored to the single byte (not to sizeof(bool) bytes!)

References append_byte().

void append_data ( const byte_t *const   data_to_copy,
const size_int_t  size_to_copy 
)

Writes `size_to_copy' bytes from `data_to_copy' to the message.

Parameters:
data_to_copy = pointer to the sequence of bytes
size_to_copy = number of bytes to copy from the byte sequence given in data_to_copy

void append_state ( const state_t  state  ) 

Writes a complete representation of state to the message.

Parameters:
state = state to copy to the message
Writes `state.size' and the byte sequence referenced by `state.ptr' to the message

References state_t::ptr, and state_t::size.

size_int_t get_written_size (  )  const [inline]

Returns a size of part of the message, where something has been written using append_* methods

Referenced by network_t::send_message(), and network_t::send_urgent_message().

void load_data ( byte_t *const   new_data,
const size_int_t  new_allocated_size 
) [inline]

Replaces a data in a message by given data (using memory copying).

Writes a given byte sequence to the begin of the message. The reading head in rewound to the begin of the message, writting head is moved to the end of new message content.

Implemented simply as this->rewind(); this->append_data(new_data, new_allocated_size);

void read_data ( char *const   data_to_copy,
const std::size_t  size_to_copy 
)

Copies `size_to_copy' bytes from the message to `data_to_copy'.

Parameters:
data_to_copy = the pointer to the byte sequence at least data_to_copy bytes long
size_to_copy = count of bytes to copy from the message

void read_state ( state_t state  ) 

Copies a state stored in the message to `state'.

Parameters:
state = the state which will be rewritten by the copy of state stored in the message
Warning:
This method does not deallocate the byte sequence in state.ptr. This method allocated a new memory space and the user is reponsible for a deallocation of written state.ptr.

void rewind (  )  [inline]

Moves both reading and writting heads to the beginning of the message.

Then get_written_size() will return 0, append_* methods will write from the beginning of the message and read_* methods will read from the beginning of the message Use this method if you do not care of the stored message and you want to write a new message to the same instance of this class.

void rewind_append (  )  [inline]

Moves a writting head to the beginning of the message.

Then get_written_size() will return 0 and append_* methods will write from the beginning of the message. Use this method if you do not care of the stored message and you want to write a new message to the same instance of this class.

void rewind_read (  )  [inline]

Moves a reading head to the beginning of the message.

Then all read_* methods will read from the beginning of the message

void set_data ( byte_t *const   new_data,
const size_int_t  new_allocated_size 
)

Sets a byte sequence stored in a message.

The same as message_t::set_data(new_data,new_allocated_size,new_allocated_size)

Warning:
The byte sequence set by this method will be deallocated in a destructor! If you do not like this behavior, use a method load_data().

void set_data ( byte_t *const   new_data,
const size_int_t  new_allocated_size,
const size_int_t  new_written_size 
)

Sets a byte sequence stored in a message.

Parameters:
new_data = byte sequence to store in a message
new_allocated_size = size in bytes of the memory referenced by new_data
new_written_size = the number of bytes, which are already written in the message (valid bytes)
Warning:
The byte sequence set by this method will be deallocated in a destructor! If you do not like this behavior, use a method load_data().

Referenced by network_t::receive_message().

void set_written_size ( const size_int_t  new_size  )  [inline]

Sets a size of written part of message.

It can be useful if you need to write a part of message directly to the memory referenced by get_data().

Referenced by network_t::receive_message().


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

Reference Manual for Library, 2006 developed in ParaDiSe laboratory, Faculty of Informatics, Masaryk University