Socket: Move protocol into the socket body (as private base class) and allow non...
[senf.git] / HowTos / NewPacket / Mainpage.dox
index a932cb8..e9cca96 100644 (file)
@@ -20,7 +20,7 @@
 // Free Software Foundation, Inc.,
 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
-/** \mainpage HowTo: Defining and using a new 'libPacket' Packet Type 
+/** \mainpage Defining and using a new 'libPacket' Packet Type 
 
     This howto will introduce the facilities needed to define a new packet type. As example, the
     \c GREPacket type is defined. 
 
     \section howto_newpacket_type Defining the packet type
 
-    After we have implemented the \c GREPacketParser we need now to build the packet type. This is
+    After we have implemented the \c GREPacketParser we now need to build the packet type. This is
     done by providing a special policy class called the 'packet type'. This class encapsulates all
     the information the packet library needs to know about a packet:
 
     \code
     static void finalize(packet p) 
     {
+        p->protocolType() << key(p.next(senf::nothrow));
         if (p->checksumPresent())
             p->checksum() << p->calculateChecksum();
-        p->protocolType() << key(p.next(senf::nothrow));
     }
     \endcode
     
-    \a finalize() first updates the \a checksum() field if present. It then sets the \a
-    protocolType() field depending on the \e next packet. The \c key() function is provided by the
-    mixin class: It will lookup the \e type of a packet in the registry and return that packets key
-    in the registry.
+    \a finalize() firs sets the \a protocolType() field depending on the \e next packet. The \c
+    key() function is provided by the mixin class: It will lookup the \e type of a packet in the
+    registry and return that packets key in the registry. 
+
+    It then updates the \a checksum() field if present (this always needs to be done last since the
+    checksum depends on the other field values).
 
     Here we are using the more generic parser assignment expressed using the \c << operator. This
     operator in the most cases works like an ordinary assignment, however it can also be used to
         static key_t nextPacketKey(packet p) { return p->protocolType(); }
     
         static void finalize(packet p) {
+            p->protocolType() << key(p.next(senf::nothrow)); 
             if (p->checksumPresent()) p->checksum() << p->calculateChecksum();
-            p->protocolType() << key(p.next(senf::nothrow));
-        }
+       }
     
         static void dump(packet p, std::ostream & os);
     };
     GREPacket.hh:
 
     \code
-    #ifndef GRE_PACKET_HH
-    #define GRE_PACKET_HH
+    #ifndef HH_GREPacket_
+    #define HH_GREPacket_
 
     #include <senf/Packets.hh>
     
             { return p->valid() ? lookup(p->protocolType()) : no_factory(); }
     
         static void finalize(packet p) {
-            if (p->checksumPresent()) p->checksum() << p->calculateChecksum();
             p->protocolType() << key(p.next(senf::nothrow));
+            if (p->checksumPresent()) p->checksum() << p->calculateChecksum();
         }
     
         static void dump(packet p, std::ostream & os);
     documentation of all the packet parser macros.</td></tr>
     
     <tr><td>\ref parseint, \n \ref parsecollection</td> <td>There are several lists of available
-    reusable packet parsers: . However, this list is not complete as there are other protocol
+    reusable packet parsers. However, these lists are not complete as there are other protocol
     specific reusable parsers (without claiming to be exhaustive: senf::INet4AddressParser,
     senf::INet6AddressParser, senf::MACAddressParser)</td></tr>
 
 // indent-tabs-mode: nil
 // ispell-local-dictionary: "american"
 // compile-command: "scons -u doc"
-// mode: flyspell
 // mode: auto-fill
 // End: