|
| 1 | +The message template |
| 2 | +==================== |
| 3 | + |
| 4 | +One of the core components in the library is the concept and the implementation |
| 5 | +of a common message type. In most (not all) network protocols, the concept of a |
| 6 | +message is central to the definition of the protocol. In HTTP, SMTP, XMPP, and |
| 7 | +even other protocols like SNMP and ICMP, there is a common notion of a "packet" |
| 8 | +or a message. In cpp-netlib we chose to implement the concept of a message that |
| 9 | +has the following common parts: |
| 10 | + |
| 11 | + * **Source** - every message has a source identifier which varies from |
| 12 | + protocol to protocol. |
| 13 | + |
| 14 | + * **Destination** - every message has a destination identifier which varies |
| 15 | + from protocol to protocol. |
| 16 | + |
| 17 | + * **Headers** - each message is assumed to contain headers, which may be empty |
| 18 | + in cases where the protocol does not support it, but is nonetheless |
| 19 | + supported by cpp-netlib messages. |
| 20 | + |
| 21 | + * **Body** - the content area of a message which varies from protocol to |
| 22 | + protocol (also sometimes referred to as payload). |
| 23 | + |
| 24 | +This division is purely logical -- in the underlying implementation, the message |
| 25 | +type can choose to have different means of storing the data, dependinn on the |
| 26 | +type used to tag the message. This section covers the `Message Concept`_ as well |
| 27 | +as the `Basic Message`_ implementation. |
| 28 | + |
| 29 | +Message Concept |
| 30 | +``````````````` |
| 31 | + |
| 32 | +The Message Concept specifies what the valid operations on a message are as well |
| 33 | +as what messages look like semantically. The following table summarize the |
| 34 | +operations and syntactic as well as semantic properties of messages. |
| 35 | + |
| 36 | +**Legend** |
| 37 | + |
| 38 | +:M: The message type. |
| 39 | +:m,n: An instance of **M**. |
| 40 | +:S: A string type. |
| 41 | +:s,k,v: An instance of **S**. |
| 42 | + |
| 43 | ++------------------------+----------------------+-------------------------------------+ |
| 44 | +| Construct | Result | Description | |
| 45 | ++========================+======================+=====================================+ |
| 46 | +| M() | Instance of M | Default constructible. | |
| 47 | ++------------------------+----------------------+-------------------------------------+ |
| 48 | +| M(m) | Instance of M | Copy constructible. | |
| 49 | ++------------------------+----------------------+-------------------------------------+ |
| 50 | +| m = n; | Reference to m | Assignable. | |
| 51 | ++------------------------+----------------------+-------------------------------------+ |
| 52 | +| swap(m, n); | ``void`` | Swappable. | |
| 53 | ++------------------------+----------------------+-------------------------------------+ |
| 54 | +| source(m); | unspecified | Retrieve the source of m. | |
| 55 | ++------------------------+----------------------+-------------------------------------+ |
| 56 | +| destination(m); | unspecified | Retrieve the destination of m. | |
| 57 | ++------------------------+----------------------+-------------------------------------+ |
| 58 | +| headers(m); | ``Range<Pair<S,S>>`` | Get the range of headers of m. | |
| 59 | ++------------------------+----------------------+-------------------------------------+ |
| 60 | +| body(m); | unspecified | Retrieve the body of m. | |
| 61 | ++------------------------+----------------------+-------------------------------------+ |
| 62 | +| m << source(s); | ``M &`` | Set the source of m. | |
| 63 | ++------------------------+----------------------+-------------------------------------+ |
| 64 | +| m << destination(s); | ``M &`` | Set the destination of m. | |
| 65 | ++------------------------+----------------------+-------------------------------------+ |
| 66 | +| m << header(k, v); | ``M &`` | Add a header to m. | |
| 67 | ++------------------------+----------------------+-------------------------------------+ |
| 68 | +| m << remove_header(k); | ``M &`` | Remove a header from m. | |
| 69 | ++------------------------+----------------------+-------------------------------------+ |
| 70 | +| m << body(s); | ``M &`` | Set the body of m. | |
| 71 | ++------------------------+----------------------+-------------------------------------+ |
| 72 | + |
| 73 | +Types that model the Message Concept are meant to encapsulate data that has a |
| 74 | +source, a destination, one or more named headers, and a body/payload. Because |
| 75 | +the accessors and the directives are not required to be part of the message type |
| 76 | +that models the Message Concept, a message can be implemented as a POD type and |
| 77 | +have all manipulations performed in the directive implementations, as well as |
| 78 | +value transformations done in the accessors. |
| 79 | + |
| 80 | +Basic Message |
| 81 | +````````````` |
| 82 | +The default implementation of a simple type that models the Message Concept is |
| 83 | +available in cpp-netlib. This default implementation is named ``basic_message`` |
| 84 | +which supports a ``Tag`` template parameter. The definition of ``basic_message`` |
| 85 | +looks like this: |
| 86 | + |
| 87 | +:: |
| 88 | + |
| 89 | + template <class Tag> |
| 90 | + struct basic_message; |
| 91 | + |
| 92 | +The ``basic_message`` template requires that the following tag-dispatched |
| 93 | +metafunctions are defined for the type ``Tag``: |
| 94 | + |
| 95 | +:: |
| 96 | + |
| 97 | + template <class Tag> |
| 98 | + struct string; |
| 99 | + |
| 100 | + template <class Tag> |
| 101 | + struct headers_container; |
| 102 | + |
| 103 | +All the operations defined by the message concept are implemented by this basic |
| 104 | +message type. Other message implementations can either use this common message |
| 105 | +type or specialize it according to whether they want to use different containers |
| 106 | +or whether it's going to be just a POD type. |
0 commit comments