cpp-msgpack-rpc
0.2.0
An RPC library implementing MessagePack RPC.
Toggle main menu visibility
Loading...
Searching...
No Matches
parsed_parameters.h
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
#pragma once
21
22
#include <memory>
23
#include <tuple>
24
#include <utility>
25
26
#include <msgpack.hpp>
27
28
#include "
msgpack_rpc/common/msgpack_rpc_exception.h
"
29
#include "
msgpack_rpc/common/status_code.h
"
30
31
namespace
msgpack_rpc::messages
{
32
36
class
ParsedParameters
{
37
public
:
44
explicit
ParsedParameters
(
45
msgpack::object
object
, std::shared_ptr<msgpack::zone> zone)
46
:
object_
(object),
zone_
(
std
::move(zone)) {
47
if
(
object
.type != msgpack::type::ARRAY) {
48
throw
MsgpackRPCException
(
49
StatusCode::INVALID_MESSAGE,
"Invalid type of parameters."
);
50
}
51
}
52
59
template
<
typename
... Parameters>
60
[[nodiscard]] std::tuple<Parameters...>
as
()
const
{
61
try
{
62
// msgpack library doesn't check the number of elements in tuples.
63
if
(
object_
.via.array.size !=
sizeof
...(Parameters)) {
64
throw
MsgpackRPCException
(StatusCode::INVALID_MESSAGE,
65
"Invalid number of parameters."
);
66
}
67
return
object_
.as<std::tuple<Parameters...>>();
68
}
catch
(
const
msgpack::type_error&) {
69
throw
MsgpackRPCException
(
70
StatusCode::TYPE_ERROR,
"Invalid types of parameters."
);
71
}
72
}
73
74
private
:
76
msgpack::object
object_
;
77
79
std::shared_ptr<msgpack::zone>
zone_
;
80
};
81
82
}
// namespace msgpack_rpc::messages
msgpack_rpc::MsgpackRPCException
Class of exceptions in cpp-msgpack-rpc library.
Definition
msgpack_rpc_exception.h:35
msgpack_rpc::messages::ParsedParameters::object_
msgpack::object object_
Object of parameters in msgpack library.
Definition
parsed_parameters.h:76
msgpack_rpc::messages::ParsedParameters::zone_
std::shared_ptr< msgpack::zone > zone_
Zone in msgpack library.
Definition
parsed_parameters.h:79
msgpack_rpc::messages::ParsedParameters::ParsedParameters
ParsedParameters(msgpack::object object, std::shared_ptr< msgpack::zone > zone)
Constructor.
Definition
parsed_parameters.h:44
msgpack_rpc::messages::ParsedParameters::as
std::tuple< Parameters... > as() const
Get parameters as given types.
Definition
parsed_parameters.h:60
msgpack_rpc_exception.h
Definition of MsgpackRPCException class.
msgpack_rpc::messages
Namespace of messages.
Definition
buffer_view.h:24
std
STL namespace.
status_code.h
Definition of StatusCode enumeration.
include
msgpack_rpc
messages
parsed_parameters.h
Generated on
for cpp-msgpack-rpc by
1.18.0