userver: userver/dump/unsafe.hpp Source File
Loading...
Searching...
No Matches
unsafe.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/dump/unsafe.hpp
4/// @brief Low-level unsafe dump read/write helpers
5
6#include <string_view>
7
8#include <userver/dump/operations.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace dump {
13
14/// @brief Writes a non-size-prefixed `std::string_view`
15/// @note `writer.Write(str)` should normally be used instead to write strings
16void WriteStringViewUnsafe(Writer& writer, std::string_view value);
17
18/// @brief Reads a `std::string_view`
19/// @warning The `string_view` will be invalidated on the next `Read` operation
20std::string_view ReadStringViewUnsafe(Reader& reader);
21
22/// @brief Reads a non-size-prefixed `std::string_view`
23/// @note The caller must somehow know the string size in advance
24/// @warning The `string_view` will be invalidated on the next `Read` operation
25std::string_view ReadStringViewUnsafe(Reader& reader, std::size_t size);
26
27/// @brief Reads a `std::string_view`
28/// @note Normally, exactly `max_size` bytes is returned. On end-of-file,
29/// the amount of bytes returned can be less than `max_size`.
30/// @warning The `string_view` will be invalidated on the next `Read` operation
31std::string_view ReadUnsafeAtMost(Reader& reader, std::size_t max_size);
32
33/// @brief Moves the internal cursor back by `size` bytes
34/// so that the next call to @ref ReadUnsafeAtMost returns the same data again
35/// @note If there has been no previous call to @ref ReadUnsafeAtMost,
36/// or the last read operation was performed using something except
37/// @ref ReadUnsafeAtMost,
38/// or `size` is greater than the number of bytes returned,
39/// then the behavior is undefined.
40void BackUpReadUnsafe(Reader& reader, std::size_t size);
41
42} // namespace dump
43
44USERVER_NAMESPACE_END