BodyWriter.qbk 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. [/
  2. Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. Official repository: https://github.com/boostorg/beast
  6. ]
  7. [section:BodyWriter BodyWriter]
  8. A [*BodyWriter] provides an
  9. [@https://en.wikipedia.org/wiki/Online_algorithm online algorithm]
  10. to obtain a sequence of zero
  11. or more buffers from a body during serialization. The implementation creates
  12. an instance of this type when needed, and calls into it one or more times to
  13. retrieve buffers holding body octets. The interface of [*BodyWriter] is
  14. intended to obtain buffers for these scenarios:
  15. * A body that does not entirely fit in memory.
  16. * A body produced incrementally from coroutine output.
  17. * A body represented by zero or more buffers already in memory.
  18. * A body whose size is not known ahead of time.
  19. * Body data generated dynamically from other threads.
  20. * Body data computed algorithmically.
  21. [heading Associated Types]
  22. * [link beast.ref.boost__beast__http__is_body_writer `is_body_writer`]
  23. * __Body__
  24. [heading Requirements]
  25. [warning
  26. These requirements may undergo non-backward compatible
  27. changes in subsequent versions.
  28. ]
  29. In this table:
  30. * `W` denotes a type meeting the requirements of [*BodyWriter].
  31. * `B` denotes a __Body__ where
  32. `std::is_same<W, B::writer>::value == true`.
  33. * `a` denotes a value of type `W`.
  34. * `h` denotes a const value of type `header<isRequest, Fields> const&`.
  35. * `v` denotes a possibly const value of type `Body::value_type&`.
  36. * `ec` is a value of type [link beast.ref.boost__beast__error_code `error_code&`].
  37. * `W<T>` is the type `boost::optional<std::pair<T, bool>>`.
  38. [table Valid expressions
  39. [[Expression] [Type] [Semantics, Pre/Post-conditions]]
  40. [
  41. [`W::const_buffers_type`]
  42. []
  43. [
  44. A type which meets the requirements of __ConstBufferSequence__.
  45. This is the type of buffer returned by `W::get`.
  46. ]
  47. ][
  48. [`W{h,v};`]
  49. []
  50. [
  51. Constructible from `h` and `v`. The lifetime of `h` and `v`
  52. are guaranteed to end no earlier than after the `W` is destroyed.
  53. The writer shall not access the contents of `h` or `v` before
  54. the first call to `init`, permitting lazy construction of the
  55. message.
  56. The constructor may optionally require that `h` and `v` are
  57. `const` references, with these consequences:
  58. * If `W` requires that `h` and `v` are const references, then
  59. the corresponding serializer constructors for messages with this
  60. body type will will accept a const reference to a message,
  61. otherwise:
  62. * If `W` requires that `h` and `v` are non-const references,
  63. then the corresponding serializer constructors for messages with
  64. this body type will require a non-const reference to a message.
  65. ]
  66. ][
  67. [`a.init(ec)`]
  68. []
  69. [
  70. Called once to fully initialize the object before any calls to
  71. `get`. The message body becomes valid before entering this function,
  72. and remains valid until the writer is destroyed.
  73. The function will ensure that `!ec` is `true` if there was
  74. no error or set to the appropriate error code if there was one.
  75. ]
  76. ][
  77. [`a.get(ec)`]
  78. [`W<W::const_buffers_type>`]
  79. [
  80. Called one or more times after `init` succeeds. This function
  81. returns `boost::none` if all buffers representing the body have
  82. been returned in previous calls or if it sets `ec` to indicate an
  83. error. Otherwise, if there are buffers remaining the function
  84. should return a pair with the first element containing a non-zero
  85. length buffer sequence representing the next set of octets in
  86. the body, while the second element is a `bool` meaning `true`
  87. if there may be additional buffers returned on a subsequent call,
  88. or `false` if the buffer returned on this call is the last
  89. buffer representing the body.
  90. The function will ensure that `!ec` is `true` if there was
  91. no error or set to the appropriate error code if there was one.
  92. ]
  93. ]]
  94. [heading Exemplar]
  95. [concept_BodyWriter]
  96. [heading Models]
  97. * [link beast.ref.boost__beast__http__basic_dynamic_body.writer `basic_dynamic_body::writer`]
  98. * [link beast.ref.boost__beast__http__basic_file_body__writer `basic_file_body::writer`]
  99. * [link beast.ref.boost__beast__http__basic_string_body.writer `basic_string_body::writer`]
  100. * [link beast.ref.boost__beast__http__buffer_body.writer `buffer_body::writer`]
  101. * [link beast.ref.boost__beast__http__empty_body.writer `empty_body::writer`]
  102. * [link beast.ref.boost__beast__http__span_body.writer `span_body::writer`]
  103. * [link beast.ref.boost__beast__http__vector_body.writer `vector_body::writer`]
  104. [endsect]