cpp-msgpack-rpc
0.2.0
An RPC library implementing MessagePack RPC.
Toggle main menu visibility
Loading...
Searching...
No Matches
parse_toml.cpp
Go to the documentation of this file.
1
/*
2
* Copyright 2023 MusicScience37 (Kenta Kabashima)
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
20
#include "
msgpack_rpc/config/toml/parse_toml.h
"
21
22
#include <fmt/format.h>
23
#include <toml++/toml.h>
24
25
#include "
msgpack_rpc/common/msgpack_rpc_exception.h
"
26
#include "
msgpack_rpc/common/status.h
"
27
#include "
msgpack_rpc/common/status_code.h
"
28
#include "
msgpack_rpc/config/toml/parse_toml_root.h
"
29
30
namespace
msgpack_rpc::config::toml {
31
32
void
parse_toml
(std::string_view file_path,
33
std::unordered_map<std::string, LoggingConfig>& logging_configs,
34
std::unordered_map<std::string, ClientConfig>& client_configs,
35
std::unordered_map<std::string, ServerConfig>& server_configs) {
36
try
{
37
const
auto
root_table = ::toml::parse_file(file_path);
38
impl::parse_toml
(
39
root_table, logging_configs, client_configs, server_configs);
40
}
catch
(
const
MsgpackRPCException
& e) {
41
throw
MsgpackRPCException
(StatusCode::INVALID_ARGUMENT,
42
fmt::format(
43
"Failed to parse {}: {}"
, file_path, e.
status
().
message
()));
44
}
catch
(const ::toml::parse_error& e) {
45
throw
MsgpackRPCException
(StatusCode::INVALID_ARGUMENT,
46
fmt::format(
"Failed to parse {}: {} (at {}:{})"
, file_path,
47
e.description(), file_path, e.source().begin.line));
48
}
49
}
50
51
}
// namespace msgpack_rpc::config::toml
msgpack_rpc::MsgpackRPCException
Class of exceptions in cpp-msgpack-rpc library.
Definition
msgpack_rpc_exception.h:35
msgpack_rpc::common::MsgpackRPCException::status
const Status & status() const noexcept
Get the status.
Definition
msgpack_rpc_exception.cpp:34
msgpack_rpc::common::Status::message
std::string_view message() const noexcept
Get the error message.
Definition
status.cpp:76
msgpack_rpc_exception.h
Definition of MsgpackRPCException class.
msgpack_rpc::config::toml::parse_toml
void parse_toml(std::string_view file_path, std::unordered_map< std::string, LoggingConfig > &logging_configs, std::unordered_map< std::string, ClientConfig > &client_configs, std::unordered_map< std::string, ServerConfig > &server_configs)
Parse configurations from a TOML file.
Definition
parse_toml.cpp:32
parse_toml.h
Definition of parse_toml functions.
msgpack_rpc::config::toml::impl::parse_toml
void parse_toml(const ::toml::table &table, MessageParserConfig &config)
Parse a configuration of parsers of messages from TOML.
Definition
parse_toml_client_server.h:46
parse_toml_root.h
Implementation of parse_toml functions.
status.h
Definition of Status class.
status_code.h
Definition of StatusCode enumeration.
src
msgpack_rpc
config
toml
parse_toml.cpp
Generated on
for cpp-msgpack-rpc by
1.18.0