JSON-RPC 2.0
JSON-RPC 2.0 Modern C++ Library
Loading...
Searching...
No Matches
framed_transport.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <istream>
5#include <ostream>
6#include <string>
7#include <unordered_map>
8
9namespace jsonrpc::transport {
10
11class FramedTransportTest;
12
20 using HeaderMap = std::unordered_map<std::string, std::string>;
21
22 protected:
24 static constexpr const char *kHeaderDelimiter = "\r\n\r\n";
25
35 static void FrameMessage(std::ostream &output, const std::string &message);
36
37 static auto ReadHeadersFromStream(std::istream &input) -> HeaderMap;
38 static auto ReadContentLengthFromStream(std::istream &input) -> int;
39
47 static auto ReadContent(std::istream &input, std::size_t content_length)
48 -> std::string;
49
59 static auto ReceiveFramedMessage(std::istream &input) -> std::string;
60
61 private:
68 static auto ParseContentLength(const std::string &header_value) -> int;
69
70 friend class FramedTransportTest;
71};
72
73} // namespace jsonrpc::transport
Base class for framed transport mechanisms.
static constexpr const char * kHeaderDelimiter
The delimiter used to separate headers from the message content.
static auto ReadContentLengthFromStream(std::istream &input) -> int
static auto ReceiveFramedMessage(std::istream &input) -> std::string
Receives a framed message.
static auto ReadContent(std::istream &input, std::size_t content_length) -> std::string
Reads content from the input stream based on the content length.
static auto ReadHeadersFromStream(std::istream &input) -> HeaderMap
static void FrameMessage(std::ostream &output, const std::string &message)
Constructs a framed message.