cpp-msgpack-rpc
0.2.0
An RPC library implementing MessagePack RPC.
Toggle main menu visibility
Loading...
Searching...
No Matches
message_parser.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 <cstddef>
23
#include <optional>
24
25
#include <msgpack.hpp>
26
27
#include "
msgpack_rpc/config/message_parser_config.h
"
28
#include "msgpack_rpc/impl/msgpack_rpc_export.h"
29
#include "
msgpack_rpc/messages/buffer_view.h
"
30
#include "
msgpack_rpc/messages/parsed_message.h
"
31
32
namespace
msgpack_rpc::messages
{
33
37
class
MSGPACK_RPC_EXPORT
MessageParser
{
38
public
:
44
explicit
MessageParser
(
const
config::MessageParserConfig
&
config
);
45
46
MessageParser
(
const
MessageParser
&) =
delete
;
47
MessageParser
(
MessageParser
&&) =
delete
;
48
MessageParser
& operator=(
const
MessageParser
&) =
delete
;
49
MessageParser
& operator=(
MessageParser
&&) =
delete
;
50
54
~MessageParser
();
55
61
BufferView
prepare_buffer
();
62
68
void
consumed
(std::size_t num_bytes);
69
76
[[nodiscard]] std::optional<ParsedMessage>
try_parse
();
77
78
private
:
80
msgpack::unpacker
parser_
;
81
83
std::size_t
read_buffer_size_
;
84
};
85
86
}
// namespace msgpack_rpc::messages
buffer_view.h
Definition of BufferView class.
msgpack_rpc::config::MessageParserConfig
Class of configuration of parsers of messages.
Definition
message_parser_config.h:31
msgpack_rpc::messages::BufferView
Class of buffers without memory management.
Definition
buffer_view.h:29
msgpack_rpc::messages::MessageParser::~MessageParser
~MessageParser()
Destructor.
msgpack_rpc::messages::MessageParser::read_buffer_size_
std::size_t read_buffer_size_
Buffer size to read at once.
Definition
message_parser.h:83
msgpack_rpc::messages::MessageParser::try_parse
std::optional< ParsedMessage > try_parse()
Try to parse a message and return it if parsed, throw an exception if the message data is invalid.
Definition
message_parser.cpp:45
msgpack_rpc::messages::MessageParser::consumed
void consumed(std::size_t num_bytes)
Set some bytes to be consumed.
Definition
message_parser.cpp:41
msgpack_rpc::messages::MessageParser::MessageParser
MessageParser(const config::MessageParserConfig &config)
Constructor.
Definition
message_parser.cpp:31
msgpack_rpc::messages::MessageParser::prepare_buffer
BufferView prepare_buffer()
Prepare a buffer.
Definition
message_parser.cpp:36
msgpack_rpc::messages::MessageParser::parser_
msgpack::unpacker parser_
Parser.
Definition
message_parser.h:80
message_parser_config.h
Definition of MessageParserConfig class.
msgpack_rpc::config
Namespace of configurations.
Definition
client_config.h:32
msgpack_rpc::messages
Namespace of messages.
Definition
buffer_view.h:24
parsed_message.h
Definition of ParsedMessage type.
include
msgpack_rpc
messages
message_parser.h
Generated on
for cpp-msgpack-rpc by
1.18.0