C4 Engine
C4 Engine API Documentation

class Message

Defined in:  C4Messages.h
Base class for all message types.
Definition

class Message : public ListElement<Message>, public Memory<MessageMgr>

Member Functions
Message::GetMessageType Returns the dynamic type identifier of a message.
Message::GetMessageFlags Returns flags indicating whether a message requires special handling.
Message::SetMessageFlags Sets flags indicating whether a message requires special handling.
Message::CompressMessage Called by the Message Manager to compress and serialize message data into a memory buffer.
Message::DecompressMessage Called by the Message Manager to decompress and validate message data stored in a memory buffer.
Message::HandleMessage Called by the Message Manager to respond to a received message.
Constructor

Message(MessageType type, uint32 flags = 0);

Parameters
type The type of message.
flags The message flags.
Description
Every type of message is encapsulated by a subclass of the Message class. The type parameter passed to the Message constructor identifies the type of message being constructed and should be passed in from the constructor of a subclass.

Each subclass of the Message class must implement the following three functions.
  1. A default constructor that takes no parameters. When the Message Manager receives a message having an application-defined type, it calls the Application::CreateMessage function with the message type, and this function should return a newly created Message subclass corresponding to that type. The default constructor should not initialize any data fields because the Message Manager subsequently calls the object's DecompressMessage function to initialize the object using data from the received network packet.
  2. A CompressMessage function. The Message Manager calls this function to compress and serialize the message into a buffer that will be sent as a data packet.
  3. A DecompressMessage function. The Message Manager calls this function to decompress a data packet into the message object and validate its contents.
Subclasses of the Message class may have, in addition to the default constructor, constructors that take initializers. Such a constructor would be useful for creating a new message that is to be sent to another machine.
Base Classes
ListElement<Message> Used internally by the Message Manager.
Memory<MessageMgr> Memory for Message objects is allocated in the Message Manager's heap.
See Also

MessageMgr