Boost logo

Boost Users :

Subject: [Boost-users] [mpl] Suggestion on handle protocol messages
From: Daniele Barzotti (daniele.barzotti_at_[hidden])
Date: 2013-01-23 11:23:19


Dear,

I need to handle a protocol defined with Protocol Buffers.
My messages are defined as:

enum EMessages {
  E_MSG_METHOD_CONNECT = 0x8001,
  E_MSG_EVENT_CONNECT = 0xA001,
 ...
}

struct MsgHeader {
  long sessionRef;
  long transactionId;
  long status;
}

struct MSG_METHOD_CONNECT {
  Messages opCode;
  MsgHeader header;
  .. other fields ..
}

Now, I defined an interface and a template class to add a level of
indirection..

class IMessage {
  virtual INT getOpCode() = 0;
  virtual STRING getName() = 0;
  virtual size_t getSize() = 0;
  ....
}

template<class MESSAGE>
class IMessageImpl : public IMessage {
  protected:
    MESSAGE m_Message; ///< The Message Implementation
  public:
    virtual MESSAGE& getMessage() = 0;
};

Where I'll use IMessageImpl<MSG_METHOD_CONNECT> MsgConnect;

Now, the problem in this situation is to build the correct message class
on the receiving part, knowing only the Message opCode.
I would like to manage the messages with a type list or map, but I'm a
newbie in MPL...
Is there a way to define something like this:

boost::mpl::map<int, MESSAGE>

where the key is the Message opCode and the MESSAGE is the message type?

The idea was born reading this article:
http://blog.florindinu.ro/posts/message-dispatching-in-c-part-1-type-lists.html

Thanks in advance,
Daniele.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net