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