3a328a8f   
   From: grahn+nntp@snipabacken.se   
      
   On Thu, 2012-06-07, kira kira wrote:   
   > On May 27, 6:29 pm, Jorgen Grahn wrote:   
   >>   
   >> I'm guessing (based on his other posting mentioning sequence   
   >> numbers) that the messages are part of some network protocol,   
   >> perhaps an UDP-based one like GTP or L2TP. Or perhaps he's   
   >> implementing TCP ...   
   >>   
   >> I find a less object-oriented approach the best. A dumb class   
   >> RxMessage for parsing messages I receive, and TxMessage for   
   >> building messages I need to send. These would know about the   
   >> general message format only -- typically a header with message   
   >> type, sequence number, checksum and so on, followed by   
   >> type-specific data.   
   >>   
   >> I may need to both read and write MSG_TYPE_FOO messages, but   
   >> creating a single MessageFoo class would be a mistake -- reading   
   >> and writing are two completely different things.   
   >>   
   >> Also, I believe creating a fully parsing MessageFoo is often a   
   >> mistake. Some of these protocols have messages with a very rich   
   >> inner structure. There may be dozens of possible fields of various   
   >> types. Expressed as a C++ struct that can turn into dozens of   
   >> vectors, most of which are empty most of the time. A waste of   
   >> resources -- and almost as hard to interpret as the original binary   
   >> message was!   
   >>   
   >> The actual processing logic goes into other classes called things   
   >> like Retransmitter, Connection, Session, Peer ... depending on the   
   >> protocol.   
   ...   
   >   
   > So it is wise to use the normal function call with if-else loop.   
      
   At least that's what I find myself doing. Or a switch, rather. If I   
   implement a five-message protocol, I don't feel bad for having a   
   five-case switch statement somewhere in my code.   
      
   IMHO when I've just received a binary message, it's too early to turn   
   on the run-time polymorphism and have some factory build   
   FooMessage/BarMessage ... objects from it. I may not even have a real   
   reason to copy data from the input buffer.   
      
   But you still haven't provided any details, so I'm still talking about   
   things *I've* done and hoping this is relevant to your problem.   
      
   > Template is not suitable for this case, right?   
      
   Which case -- yours or mine? I do think templates are useful when   
   implementing message servers in general, but I cannot say exactly how.   
      
   Perhaps others have ready-made architectural ideas about templates. I   
   just keep an eye open, and when I see that I can simplify the code   
   with a template, I do it.   
      
   /Jorgen   
      
   --   
    // Jorgen Grahn O o .   
      
      
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|