cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
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 */
21
22#include <fmt/format.h>
23#include <toml++/toml.h>
24
29
30namespace msgpack_rpc::config::toml {
31
32void 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);
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
Class of exceptions in cpp-msgpack-rpc library.
const Status & status() const noexcept
Get the status.
std::string_view message() const noexcept
Get the error message.
Definition status.cpp:76
Definition of MsgpackRPCException class.
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 of parse_toml functions.
void parse_toml(const ::toml::table &table, MessageParserConfig &config)
Parse a configuration of parsers of messages from TOML.
Implementation of parse_toml functions.
Definition of Status class.
Definition of StatusCode enumeration.