4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Packet public header */
26 #ifndef HH_SENF_Packets_Packet_
27 #define HH_SENF_Packets_Packet_ 1
30 #include <boost/operators.hpp>
31 #include <boost/utility.hpp>
32 #include <boost/type_traits/is_integral.hpp>
33 #include <senf/Utils/Tags.hh>
34 #include <senf/Utils/safe_bool.hh>
35 #include "PacketInterpreter.hh"
37 //#include "Packet.mpp"
38 ///////////////////////////////hh.p////////////////////////////////////////
42 /** \defgroup packet_module Packet Handling
44 The basic groundwork of the %Packet library is the packet handling:
46 \li The packet classes provide access to a chain of packet headers (more generically called
48 \li They automatically manage the required memory resources and the shared packet data.
50 \section packet_module_chain The Interpreter Chain
52 The central data structure for a packet is the interpreter chain
54 \image html structure.png The Interpreter Chain
56 This image depicts a packet with several headers. Each interpreter is responsible for a
57 specific sub-range of the complete packet. This range always \e includes the packets payload
58 (This is, why we call the data structure interpreter and not header: The interpreter is
59 responsible for interpreting a range of the packet according to a specific protocol), the
60 packet interpreters are nested inside each other.
62 For each interpreter, this structure automatically divides the packet into three areas (each
63 of which are optional): The header, the payload and the trailer. Every packet will have
64 either a header or a payload section while most don't have a trailer.
66 As user of the library you always interact with the chain through one (or more) of the
67 interpreters. The interpreter provides methods to traverse to the following or preceding
68 header (interpreter) and provides two levels of access to the packet data: Generic low-level
69 access in the form of an STL compatible sequence and access to the parsed fields which are
70 provided by the parser associated with the concrete packet type.
72 \section packet_module_management Resource Management
74 The interface to the packet library is provided using a handle class (\ref Packet for
75 generic, protocol agnostic access and \ref ConcretePacket derived from \ref Packet to access
76 a specific protocol). This handle automatically manages the resources associated with the
77 packet (the interpreter chain and the data storage holding the packet data). The resources
78 are automatically released when the last packet handle referencing a specific packet is
81 \implementation The packet chain is provided on two levels: The internal representation \ref
82 PacketInterpreterBase and \ref PacketInterpreter which are referenced by the Handle
83 classes \ref Packet and \ref ConcretePacket. \n
84 The internal representation classes are pertinent in the sense, that they exist
85 regardless of the existence of a handle referencing them (as long as the packet
86 exists). Still the interpreter chain is lazy and packet interpreters beside the first
87 are only created dynamically when accessed (this is implemented in the handle not in the
88 internal representation). \n
89 The packet interpreters make use of a pool allocator. This provides extremely efficient
90 creation and destruction of packet interpreter's and removes the dynamic memory
91 management overhead from the packet interpreter management. The packet implementation
92 class (\ref PacketImpl which holds the packet data itself) however is still dynamically
93 managed (however there is only a single instance for each packet).
96 template <class PackeType> class ConcretePacket;
98 ///\addtogroup packet_module
101 /** \brief Main %Packet class
103 %Packet is the main externally visible class of the packet library. %Packet is a handle into
104 the internal packet representation. From %Packet you may access the data of that specific
105 sub-packet/header/interpreter and navigate to the neighboring
106 sub-packets/headers/interpreters.
108 %Packet is protocol agnostic. This class only provides non-protocol dependent members. To
109 access the protocol specific features of a packet (like header fields) the ConcretePacket
110 class extending %Packet is provided.
112 \section packet_semantics Semantics
114 All operations accessing the data of \c this packet in some way will ignore any preceding
115 packets/headers/interpreters in the chain. It does not matter, whether a given packet is
116 taken from the middle or the beginning of the chain, all operations (except those explicitly
117 accessing the chain of course) should work the same.
119 This especially includes members like clone() or append(): clone() will clone \e only from
120 \c this packet until the end of the chain, append() will append the given packet \e ignoring
121 any possibly preceding packets/headers/interpreters.
123 In the same way, the data() member provides an STL-sequence compatible view of the packet
124 data. This only includes the data which is part of \c this packet including header, trailer
125 \e and payload but \e not the headers or trailers of packets \e before \c this packet in the
126 packet/header/interpreter chain (nonetheless, this data overlaps with the data of other
129 Several members are member templates taking an \a OtherPacket template parameter. This
130 parameter must be the ConcretePacket instantiation associated with some concrete packet type
131 (protocol). For each implemented protocol, typedefs should be provided for these
132 instantiations (Example: \ref EthernetPacket is a typedef for
133 \ref ConcretePacket < \ref EthernetPacketType >).
136 \ref ConcretePacket for the %type specific interface\n
137 \ref PacketData for the sequence interface\n
138 \ref packetparser for a specification of the parser interface
141 : public safe_bool<Packet>,
142 public boost::equality_comparable<Packet>
145 ///////////////////////////////////////////////////////////////////////////
148 typedef void type; ///< Type of the packet.
149 typedef senf::detail::packet::size_type size_type;
150 ///< Unsigned type to represent packet size
151 typedef PacketInterpreterBase::factory_t factory_t; ///< Packet factory type (see below)
153 ///////////////////////////////////////////////////////////////////////////
154 ///\name Structors and default members
157 // default copy constructor
158 // default copy assignment
159 // default destructor
161 Packet(); ///< Create uninitialized packet handle
162 /**< An uninitialized handle is in - valid(). It does not
163 allow any operation except assignment and checking for
165 Packet clone() const; ///< Create copy packet
166 /**< clone() will create a complete copy of \c this
167 packet. The returned packet will have the same data and
168 packet chain. It does however not share any data with
169 the original packet. */
171 // conversion constructors
173 template <class PacketType>
174 Packet(ConcretePacket<PacketType> const & packet);
175 ///< Copy-construct Packet from ConcretePacket
176 /**< This constructor allows to convert an arbitrary
177 ConcretePacket into a general Packet, loosing the
178 protocol specific interface. */
181 ///////////////////////////////////////////////////////////////////////////
183 ///\name Interpreter chain access
186 Packet next() const; ///< Get next packet in chain
187 /**< \throws InvalidPacketChainException if no next packet
189 Packet next(NoThrow_t) const; ///< Get next packet in chain
190 /**< \returns in - valid() packet if no next packet
192 template <class OtherPacket> OtherPacket next() const;
193 ///< Get next packet in chain and cast to \a OtherPacket
194 /**< \throws std::bad_cast if the next() packet is not of
196 \throws InvalidPacketChainException if no next packet
198 template <class OtherPacket> OtherPacket next(NoThrow_t) const;
199 ///< Get next packet in chain and cast to \a OtherPacket
200 /**< \throws std::bad_cast if the next() packet is not of
202 \returns in - valid() packet if no next packet
204 template <class OtherPacket> OtherPacket find() const;
205 ///< Search chain forward for packet of type \a OtherPacket
206 /**< The search will start with the current packet.
207 \throws InvalidPacketChainException if no packet of
208 type \a OtherPacket can be found. */
209 template <class OtherPacket> OtherPacket find(NoThrow_t) const;
210 ///< Search chain forward for packet of type \a OtherPacket
211 /**< The search will start with the current packet.
212 \returns in - valid() packet if no packet of type \a
213 OtherPacket can be found. */
215 Packet prev() const; ///< Get previous packet in chain
216 /**< \throws InvalidPacketChainException if no previous
218 Packet prev(NoThrow_t) const; ///< Get previous packet in chain
219 /**< \returns in - valid() packet if no previous packet
221 template <class OtherPacket> OtherPacket prev() const;
222 ///< Get previous packet in chain and cast to \a OtherPacket
223 /**< \throws std::bad_cast, if the previous packet is not of
225 \throws InvalidPacketChainException if no previous
227 template <class OtherPacket> OtherPacket prev(NoThrow_t) const;
228 ///< Get previous packet in chain and cast to \a OtherPacket
229 /**< \throws std::bad_cast, if the previous packet is not of
231 \returns in - valid() packet if no previous packet
233 template <class OtherPacket> OtherPacket rfind() const;
234 ///< Search chain backwards for packet of type \a OtherPacket
235 /**< The search will start with the current packet.
236 \throws InvalidPacketChainException if no packet of
237 type \a OtherPacket can be found. */
238 template <class OtherPacket> OtherPacket rfind(NoThrow_t) const;
239 ///< Search chain backwards for packet of type \a OtherPacket
240 /**< The search will start with the current packet.
241 \returns in - valid() packet if no packet of type \a
242 OtherPacket can be found. */
245 Packet first() const; ///< Return first packet in chain
246 template <class OtherPacket> OtherPacket first() const;
247 ///< Return first packet in chain and cast
248 /**< \throws std::bad_cast if the first() packet is not of
249 type \a OtherPacket */
251 Packet last() const; ///< Return last packet in chain
252 template <class OtherPacket> OtherPacket last() const;
253 ///< Return last packet in chain and cast
254 /**< \throws std::bad_cast if the last() packet is not of
255 type \a OtherPacket */
258 template <class OtherPacket> OtherPacket parseNextAs() const;
259 ///< Interpret payload of \c this as \a OtherPacket
260 /**< parseNextAs() will throw away the packet chain after
261 the current packet if necessary. It will then parse the
262 payload section of \c this packet as given by \a
263 OtherPacket. The new packet is added to the chain after
265 \returns new packet instance sharing the same data and
266 placed after \c this packet in the chain.
267 \throws InvalidPacketChainException if no next packet
268 header is allowed (viz. nextPacketRange() of the
269 the current PacketType returns no_range() ) */
270 Packet parseNextAs(factory_t factory) const;
271 ///< Interpret payload of \c this as \a factory type packet
272 /**< parseNextAs() will throw away the packet chain after
273 the current packet if necessary. It will then parse the
274 payload section of \c this packet as given by \a
275 factory. The new packet is added to the chain after
277 \returns new packet instance sharing the same data and
278 placed after \c this packet in the chain.
279 \throws InvalidPacketChainException if no next packet
280 header is allowed (viz. nextPacketRange() of the
281 the current PacketType returns no_range() ) */
283 template <class OtherPacket> bool is() const;
284 ///< Check, whether \c this packet is of the given type
285 template <class OtherPacket> OtherPacket as() const;
286 ///< Cast current packet to the given type
287 /**< This operations returns a handle to the same packet
288 header/interpreter however upcast to the given
289 ConcretePacket type which have been instantiated
291 \throws std::bad_cast if the current packet is not of
292 type \a OtherPacket */
294 Packet append(Packet const & packet) const; ///< Append the given packet to \c this packet
295 /**< This operation will replace the payload section of \c
296 this packet with \a packet. This operation will replace
297 the packet chain after \c this packet with a clone of
298 \a packet and will replace the raw data of the payload
299 of \c this with the raw data of \a packet. \c this
300 packet will not share any data with \a packet.
301 \returns Packet handle to the cloned \a packet, placed
302 after \c this in the packet/header/interpreter
310 PacketData & data() const; ///< Access the packets raw data container
311 size_type size() const; ///< Return size of packet in bytes
312 /**< This size does \e not include the size of any preceding
313 headers/packets/interpreters. It does however include
314 \c this packets payload. */
321 template <class Annotation>
322 Annotation & annotation(); ///< Get packet annotation
323 /**< This member will retrieve an arbitrary packet
324 annotation. Every annotation is identified by a unique
325 \a Annotation type. This type should \e always be a \c
329 struct MyAnnotation {
333 senf::Packet p (...);
335 p.annotation<MyAnnotation>().value = 1;
338 Annotations are shared by all headers / interpreters
339 within a single packet chain.
341 If an annotation is \e not a POD type (more
342 specifically, if it's constructor or destructor is not
343 trivial including base classes and members), the \a
344 Annotation type \e must inherit from
345 senf::ComplexAnnotation. Failing to follow this rule
346 will result in undefined behavior and will probably
347 lead to a program crash.
350 struct MyStringAnnotation : senf::ComplexAnnotation {
354 (This type is not POD since \c std::string is not POD)
356 \see \ref packet_usage_annotation
358 \implementation The annotation system is implemented
359 quite efficiently since annotations are stored
360 within a packet embedded vector of fixed size (the
361 size is determined automatically at runtime by the
362 number of different annotations
363 used). Additionally, non-complex small annotations
364 require no additional memory management (\c new /
367 \idea Pool the annotation vectors: In the destructor
368 swap the vector into a vector graveyard (swapping
369 two vectors is an O(1) no allocation operation). In
370 the constructor, if there is a vector in the
371 graveyard, swap it in from there. Of course, it
372 would be better to do away with the vector and just
373 allocate the space together with the packet but
374 that looks quite complicated to do ... especially
375 considering that the packetimpl itself uses a pool.
380 template <class Annotation>
381 Annotation const & annotation() const; ///< Get packet annotation
382 /**< \see annotation() */
384 ///\name Other methods
387 bool operator==(Packet const & other) const; ///< Check for packet identity
388 /**< Two packet handles compare equal if they really are the
389 same packet header in the same packet chain. */
390 bool boolean_test() const; ///< Check, whether the packet is valid()
392 bool valid() const; ///< Check, whether the packet is valid()
393 /**< An in - valid() packet does not allow any operation
394 except checking for validity and assignment. in -
395 valid() packets serve the same role as 0-pointers.
397 This is an alias for boolean_test() which is called
398 when using a packet in a boolean context. */
400 void finalizeThis(); ///< Update calculated fields
401 /**< The finalize() fammily of members will update
402 calculated packet fields: checksums, size fields and so
403 on. This includes any field, which can be set from
404 other information in the packet. Each concrete packet
405 type should document, which fields are set by
408 finalizeThis() will \e only process the current
409 header. Even if only changing fields in this protocol,
410 depending on the protocol it may not be enough to
411 finalize this header only. See the packet type
414 template <class Other>
415 void finalizeTo(); ///< Update calculated fields
416 /**< The finalize() fammily of members will update
417 calculated packet fields: checksums, size fields and so
418 on. This includes any field, which can be set from
419 other information in the packet. Each concrete packet
420 type should document, which fields are set by
423 finalizeTo() will automatically process all
424 packets/headers/interpreters from the \e first
425 occurrence of packet type \a Other (beginning at \c
426 this packet searching forward towards deeper nested
427 packets) backwards up to \c this.
429 This call is equivalent to
431 p.finalizeTo(p.next<Other>())
434 void finalizeTo(Packet const & other); ///< Update calculated fields
435 /**< The finalize() fammily of members will update
436 calculated packet fields: checksums, size fields and so
437 on. This includes any field, which can be set from
438 other information in the packet. Each concrete packet
439 type should document, which fields are set by
442 finalizeTo(other) will automatically process all
443 packets/headers/interpreters beginning at \a other
444 backwards towards outer packets up to \c this. */
446 void finalizeAll(); ///< Update calculated fields
447 /**< The finalize() fammily of members will update
448 calculated packet fields: checksums, size fields and so
449 on. This includes any field, which can be set from
450 other information in the packet. Each concrete packet
451 type should document, which fields are set by
454 finalizeAll() will automatically process all
455 packets/headers/interpreters from the end of the chain
456 (the most inner packet) backwards up to \c this.
458 This call is equivalent to
460 p.finalizeTo(p.last())
463 Beware, that finalizeAll() will \e not finalize any
464 headers before \c this, it will \e only process inner
467 void dump(std::ostream & os) const; ///< Write out a printable packet representation
468 /**< This method is provided mostly to help debugging packet
469 problems. Each concrete packet should implement a dump
470 method writing out all fields of the packet in a
471 readable representation. dump() will call this member
472 for each packet/header/interpreter in the chain from \c
473 this packet up to the end of the chain. */
475 TypeIdValue typeId() const; ///< Get type of \c this packet
476 /**< This value is used e.g. in the packet registry to
477 associate packet types with other information.
478 \returns A type holding the same information as a
479 type_info object, albeit assignable */
480 factory_t factory() const; ///< Return factory instance of \c this packet
481 /**< The returned factory instance can be used to create new
482 packets of the given type without knowing the concrete
483 type of the packet. The value may be stored away for
484 later use if needed. */
486 unsigned long id() const; ///< Unique packet id
487 /**< Get a unique packet id. If two packets have the same
488 id, they share the internal data representation.. */
493 explicit Packet(PacketInterpreterBase::ptr const & packet);
495 PacketInterpreterBase::ptr const & ptr() const;
498 Packet getNext() const;
499 Packet getLast() const;
501 PacketInterpreterBase::ptr packet_;
503 template <class PacketType>
504 friend class ConcretePacket;
505 friend class PacketParserBase;
508 /** \brief Protocol specific packet handle
510 The ConcretePacket template class extends Packet to provide protocol/packet type specific
511 aspects. These are packet constructors and access to the parsed packet fields.
513 The \c PacketType template argument to ConcretePacket is a protocol specific and internal
514 policy class which defines the protocol specific behavior. To access a specific type of
515 packet, the library provides corresponding typedefs of ConcretePacket < \a SomePacketType >
516 (e.g. \ref EthernetPacket as typedef for \ref ConcretePacket < \ref EthernetPacketType >).
518 The new members provided by ConcretePacket over packet are mostly comprised of the packet
519 constructors. These come in three major flavors:
521 \li The create() family of constructors will create completely new packets.
522 \li The createAfter() family of constructors will create new packets (with new data for the
523 packet) \e after a given existing packet <em>thereby destroying and overwriting any
524 possibly existing packets and data after the given packet</em>.
525 \li The createBefore() family of constructors will create new packets (again with new data)
526 \e before a given existing packet <em>thereby destroying and overwriting any possibly
527 existing packets and data before the given packet</em>.
528 \li The createInsertBefore() family of constructors will create new packets \e before a
529 given packet \e inserting them into the packet chain after any existing packets before
532 Whereas create() will create a completely new packet with it's own chain and data storage,
533 createAfter(), createBefore() and createInsertBefore() extend a packet with additional
534 headers/interpreters. createAfter() will set the payload of the given packet to the new
535 packet whereas createBefore() and createInsertBefore() will create a new packet with the
536 existing packet as it's payload.
538 createAfter() differs from Packet::parseNextAs() in that the former creates a new packet \e
539 replacing any possibly existing data whereas the latter will interpret the already \e
540 existing data as given by the type argument.
542 \see \ref PacketTypeBase for a specification of the interface to be provided by the \a
543 PacketType policy class.
545 template <class PacketType>
550 ///////////////////////////////////////////////////////////////////////////
553 typedef PacketType type;
554 typedef typename PacketType::parser Parser;
556 ///////////////////////////////////////////////////////////////////////////
557 ///\name Structors and default members
560 // default copy constructor
561 // default copy assignment
562 // default destructor
563 // no conversion constructors
565 ConcretePacket(); ///< Create uninitialized packet handle
566 /**< An uninitialized handle is not valid(). It does not
567 allow any operation except assignment and checking for
570 static factory_t factory(); ///< Return factory for packets of specific type
571 /**< This \e static member is like Packet::factory() for a
572 specific packet of type \a PacketType */
574 // Create completely new packet
576 static ConcretePacket create(); ///< Create default initialized packet
577 /**< The packet will be initialized to it's default empty
579 static ConcretePacket create(senf::NoInit_t); ///< Create uninitialized empty packet
580 /**< This will create a completely empty and uninitialized
581 packet with <tt>size() == 0</tt>.
582 \param[in] senf::noinit This parameter must always have
583 the value \c senf::noinit. */
584 static ConcretePacket create(size_type size); ///< Create default initialized packet
585 /**< This member will create a default initialized packet
586 with the given size. If the size parameter is smaller
587 than the minimum allowed packet size an exception will
589 \param[in] size Size of the packet to create in bytes.
590 \throws TruncatedPacketException if \a size is smaller
591 than the smallest permissible size for this type of
593 static ConcretePacket create(size_type size, senf::NoInit_t);
594 ///< Create uninitialized packet
595 /**< Creates an uninitialized (all-zero) packet of the exact
597 \param[in] size Size of the packet to create in bytes
598 \param[in] senf::noinit This parameter must always have
599 the value \c senf::noinit. */
601 template <class ForwardReadableRange>
602 static ConcretePacket create(
603 ForwardReadableRange const & range,
604 typename boost::disable_if< boost::is_integral<ForwardReadableRange> >::type * = 0);
606 template <class ForwardReadableRange>
607 static ConcretePacket create(ForwardReadableRange const & range);
608 ///< Create packet from given data
609 /**< The packet will be created from a copy of the given
610 data. The data from the range will be copied directly
611 into the packet representation. The data will \e not be
612 validated in any way.
614 \param[in] range <a href="http://www.boost.org/doc/libs/release/libs/range/index.html">Boost.Range</a>
615 of data to construct packet from. */
618 // Create packet as new packet after a given packet
620 static ConcretePacket createAfter(Packet const & packet);
621 ///< Create default initialized packet after \a packet
622 /**< The packet will be initialized to it's default empty
623 state. It will be appended as next header/interpreter
624 after \a packet in that packets interpreter chain.
625 \param[in] packet Packet to append new packet to. */
626 static ConcretePacket createAfter(Packet const & packet, senf::NoInit_t);
627 ///< Create uninitialized empty packet after\a packet
628 /**< This will create a completely empty and uninitialized
629 packet with <tt>size() == 0</tt>. It will be appended
630 as next header/interpreter after \a packet in that
631 packets interpreter chain.
632 \param[in] packet Packet to append new packet to.
633 \param[in] senf::noinit This parameter must always have
634 the value \c senf::noinit. */
635 static ConcretePacket createAfter(Packet const & packet, size_type size);
636 ///< Create default initialized packet after \a packet
637 /**< This member will create a default initialized packet
638 with the given size. If the size parameter is smaller
639 than the minimum allowed packet size an exception will
640 be thrown. It will be appended as next
641 header/interpreter after \a packet in that packets
643 \param[in] packet Packet to append new packet to.
644 \param[in] size Size of the packet to create in bytes.
645 \throws TruncatedPacketException if \a size is smaller
646 than the smallest permissible size for this type of
648 static ConcretePacket createAfter(Packet const & packet, size_type size, senf::NoInit_t);
649 ///< Create uninitialized packet after \a packet
650 /**< Creates an uninitialized (all-zero) packet of the exact
651 given size. It will be appended as next
652 header/interpreter after \a packet in that packets
654 \param[in] packet Packet to append new packet to.
655 \param[in] size Size of the packet to create in bytes
656 \param[in] senf::noinit This parameter must always have
657 the value \c senf::noinit. */
659 template <class ForwardReadableRange>
660 static ConcretePacket createAfter(
661 Packet const & packet,
662 ForwardReadableRange const & range,
663 typename boost::disable_if< boost::is_integral<ForwardReadableRange> >::type * = 0);
665 template <class ForwardReadableRange>
666 static ConcretePacket createAfter(Packet const & packet,
667 ForwardReadableRange const & range);
668 ///< Create packet from given data after \a packet
669 /**< The packet will be created from a copy of the given
670 data. The data from the range will be copied directly
671 into the packet representation. The data will \e not be
672 validated in any way. It will be appended as next
673 header/interpreter after \a packet in that packets
675 \param[in] packet Packet to append new packet to.
676 \param[in] range <a href="http://www.boost.org/doc/libs/release/libs/range/index.html">Boost.Range</a>
677 of data to construct packet from. */
680 // Create packet as new packet (header) before a given packet
682 static ConcretePacket createBefore(Packet const & packet);
683 ///< Create default initialized packet before \a packet
684 /**< The packet will be initialized to it's default empty
685 state. It will be prepended as previous
686 header/interpreter before \a packet in that packets
688 \warning This constructor will destroy any existing
689 headers before \a packet and replace them with the
691 \param[in] packet Packet to prepend new packet to. */
692 static ConcretePacket createBefore(Packet const & packet, senf::NoInit_t);
693 ///< Create uninitialized empty packet before \a packet
694 /**< Creates a completely empty and uninitialized packet. It
695 will be prepended as previous header/interpreter before
696 \a packet in that packets interpreter chain.
697 \warning This constructor will destroy any existing
698 headers before \a packet and replace them with the
700 \param[in] packet Packet to prepend new packet to. */
702 static ConcretePacket createInsertBefore(Packet const & packet);
703 ///< Insert default initialized packet before \a packet
704 /**< The new packet header will be initialized to it' s
705 default empty state. It will be inserted into the
706 packet chain before \a packet.
707 \param[in] packet Packet before which to insert the new
709 static ConcretePacket createInsertBefore(Packet const & packet, senf::NoInit_t);
710 ///< Insert uninitialized empty packet before \a packet
711 /**< Inserts a completely empty and unitialized packet
712 before \a packet into the header/interpreter chain.
713 \param[in] packet Packet before which to insert the new
716 // Create a clone of the current packet
718 ConcretePacket clone() const;
721 ///////////////////////////////////////////////////////////////////////////
727 ParserProxy(Parser const & p) : p_ (p) {}
728 Parser * operator->() { return &p_; }
732 ParserProxy operator->() const; ///< Access packet fields
733 /**< This operator allows to access the parsed fields of the
734 packet using the notation <tt>packet->field()</tt>. The
735 fields of the packet are specified by the PacketType's
738 The members are not strictly restricted to simple field
739 access. The parser class may have any member which is
740 needed for full packet access (e.g. checksum validation
742 \see \ref packetparser for the parser interface. */
744 Parser parser() const; ///< Access packet field parser directly
745 /**< Access the parser of the packet. This is the same
746 object returned by the operator->() operator. The
747 operator however does not allow to access this object
748 itself, only it's members.
749 \see \ref packetparser for the parser interface */
754 typedef PacketInterpreter<PacketType> interpreter;
756 ConcretePacket(typename interpreter::ptr const & packet_);
758 typename interpreter::ptr ptr() const;
761 friend class PacketInterpreter<PacketType>;
764 /** \brief Generic parser copying
766 This operator allows to copy the value of identical parsers. This operation does \e not
767 depend on the parsers detailed implementation, it will just replace the data bytes of the
768 target parser with those from the source packet.
770 template <class PacketType, class Parser>
771 Parser operator<<(Parser target, ConcretePacket<PacketType> const & packet);
777 ///////////////////////////////hh.e////////////////////////////////////////
779 #if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_Packet_i_)
780 #define HH_SENF_Packets_Packet_i_
781 #include "Packet.cci"
783 #include "Packet.cti"
790 // c-file-style: "senf"
791 // indent-tabs-mode: nil
792 // ispell-local-dictionary: "american"
793 // compile-command: "scons -u test"
794 // comment-column: 40