Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
APIVersionParser.hpp
1#pragma once
2
3#include "rpc/common/APIVersion.hpp"
4#include "util/config/ObjectView.hpp"
5#include "util/log/Logger.hpp"
6
7#include <boost/json/object.hpp>
8
9#include <cstdint>
10#include <expected>
11#include <string>
12
13namespace rpc::impl {
14
15class ProductionAPIVersionParser : public APIVersionParser {
16 util::Logger log_{"RPC"};
17
18 uint32_t defaultVersion_;
19 uint32_t minVersion_;
20 uint32_t maxVersion_;
21
22public:
23 ProductionAPIVersionParser(
24 uint32_t defaultVersion = kAPI_VERSION_DEFAULT,
25 uint32_t minVersion = kAPI_VERSION_MIN,
26 uint32_t maxVersion = kAPI_VERSION_MAX
27 );
28
29 ProductionAPIVersionParser(util::config::ObjectView const& config);
30
31 std::expected<uint32_t, std::string>
32 parse(boost::json::object const& request) const override;
33
34 uint32_t
35 getDefaultVersion() const
36 {
37 return defaultVersion_;
38 }
39
40 uint32_t
41 getMinVersion() const
42 {
43 return minVersion_;
44 }
45
46 uint32_t
47 getMaxVersion() const
48 {
49 return maxVersion_;
50 }
51};
52
53} // namespace rpc::impl
A baseclass for API version helper.
Definition APIVersion.hpp:29
std::expected< uint32_t, std::string > parse(boost::json::object const &request) const override
Extracts API version information from a JSON object.
Definition APIVersionParser.cpp:39
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:77
Provides a view into a subset of configuration data defined by a prefix.
Definition ObjectView.hpp:21
static constexpr uint32_t kAPI_VERSION_MIN
Minimum API version supported by this build.
Definition APIVersion.hpp:19
static constexpr uint32_t kAPI_VERSION_MAX
Maximum API version supported by this build.
Definition APIVersion.hpp:24
static constexpr uint32_t kAPI_VERSION_DEFAULT
Default API version to use if no version is specified by clients.
Definition APIVersion.hpp:14