libtins  3.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Tins::Allocators Namespace Reference

Defines inner PDU allocators. More...


template<typename PDUType , typename AllocatedType >
void register_allocator (typename Internals::pdu_tag_mapper< PDUType >::type::identifier_type id)
 Registers an allocator for the provided PDU type. More...

Detailed Description

Defines inner PDU allocators.

Function Documentation

template<typename PDUType , typename AllocatedType >
void Tins::Allocators::register_allocator ( typename Internals::pdu_tag_mapper< PDUType >::type::identifier_type  id)

Registers an allocator for the provided PDU type.

Registering a certain allocator for a PDU type is useful for extending the library. Once an allocator is registered, it will be taken into account while constructing a PDU from a buffer.

If PDU finds that it cannot define which is the protocol that should be allocated based on its protocol identifier, it will try using the registered allocators if any.

// Register the 0x666 identifer. Now if EthernetII finds a
// network layer identifier field whose value is 0x666, it will
// use SomePDUType as its inner PDU type.
Allocators::register_allocator<EthernetII, SomePDUType>(0x666);

Note that some PDU types are grouped together. For example, registering an allocator for EthernetII will make it work for the rest of the link layer protocols, sine they should all work the same way.