1[/ 2 Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) 3 4 Distributed under the Boost Software License, Version 1.0. (See accompanying 5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 7 Official repository: https://github.com/boostorg/beast 8] 9 10[section Serializer Stream Operations] 11 12Non-trivial algorithms need to do more than send entire messages 13at once, such as: 14 15* Send the header first, and the body later. 16 17* Send a message incrementally: bounded work in each I/O cycle. 18 19* Use a series of caller-provided buffers to represent the body. 20 21These tasks may be performed by using the serializer stream interfaces. 22To use these interfaces, first construct an appropriate serializer 23from the message to be sent: 24 25[table Serializer 26[[Name][Description]] 27[[ 28 __serializer__ 29][ 30 ``` 31 /// Provides buffer oriented HTTP message serialization functionality. 32 template< 33 bool isRequest, 34 class Body, 35 class Fields = fields 36 > 37 class serializer; 38 ``` 39]] 40[[ 41 [link beast.ref.boost__beast__http__request_serializer `request_serializer`] 42][ 43 ``` 44 /// A serializer for HTTP/1 requests 45 template< 46 class Body, 47 class Fields = fields 48 > 49 using request_serializer = serializer<true, Body, Fields>; 50 ``` 51]] 52[[ 53 [link beast.ref.boost__beast__http__response_serializer `response_serializer`] 54][ 55 ``` 56 /// A serializer for HTTP/1 responses 57 template< 58 class Body, 59 class Fields = fields 60 > 61 using response_serializer = serializer<false, Body, Fields>; 62 ``` 63]] 64] 65 66The choices for template types must match the message passed on construction. 67This code creates an HTTP response and the corresponding serializer: 68 69[http_snippet_10] 70 71The stream operations which work on serializers are: 72 73[table Serializer Stream Operations 74[[Name][Description]] 75[[ 76 [link beast.ref.boost__beast__http__write.overload1 [*write]] 77][ 78 Send everything in a __serializer__ to a __SyncWriteStream__. 79]] 80[[ 81 [link beast.ref.boost__beast__http__async_write.overload1 [*async_write]] 82][ 83 Send everything in a __serializer__ asynchronously to an __AsyncWriteStream__. 84]] 85[[ 86 [link beast.ref.boost__beast__http__write_header.overload1 [*write_header]] 87][ 88 Send only the header from a __serializer__ to a __SyncWriteStream__. 89]] 90[[ 91 [link beast.ref.boost__beast__http__async_write_header [*async_write_header]] 92][ 93 Send only the header from a __serializer__ asynchronously to an __AsyncWriteStream__. 94]] 95[[ 96 [link beast.ref.boost__beast__http__write_some.overload1 [*write_some]] 97][ 98 Send part of a __serializer__ to a __SyncWriteStream__. 99]] 100[[ 101 [link beast.ref.boost__beast__http__async_write_some [*async_write_some]] 102][ 103 Send part of a __serializer__ asynchronously to an __AsyncWriteStream__. 104]] 105] 106 107Here is an example of using a serializer to send a message on a stream 108synchronously. This performs the same operation as calling `write(stream, m)`: 109 110[http_snippet_12] 111 112[endsect] 113