cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
serialized_message.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 <cstddef>
23#include <cstring>
24#include <utility>
25
27
28namespace msgpack_rpc::messages {
29
31 : buffer_(impl::allocate_sharable_binary(size)) {
32 // Following operations won't throw exceptions.
35}
36
39
44
46 : buffer_(std::exchange(other.buffer_, nullptr)) {}
47
49 const SerializedMessage& other) noexcept {
50 if (this == &other) {
51 return *this;
52 }
53 if (buffer_ != nullptr) {
55 }
56 buffer_ = other.buffer_;
58 return *this;
59}
60
62 SerializedMessage&& other) noexcept {
63 std::swap(buffer_, other.buffer_);
64 return *this;
65}
66
72
73const char* SerializedMessage::data() const noexcept {
75}
76
77std::size_t SerializedMessage::size() const noexcept {
78 return buffer_->binary_size;
79}
80
81} // namespace msgpack_rpc::messages
impl::SharableBinaryHeader * buffer_
Buffer.
SerializedMessage & operator=(const SerializedMessage &other) noexcept
Copy assignment operator.
const char * data() const noexcept
Get the pointer to the data.
SerializedMessage(const char *data, std::size_t size)
Constructor.
std::size_t size() const noexcept
Get the size of the data.
Namespace of internal implementations.
void decrease_reference_count_of_sharable_binary(SharableBinaryHeader *buffer) noexcept
Decrease a reference count of a buffer of sharable binary data, and deallocate the buffer if possible...
char * binary_buffer_of(SharableBinaryHeader *buffer) noexcept
Get buffer of binary data from a buffer of sharable binary data.
void add_reference_count_of_sharable_binary(SharableBinaryHeader *buffer) noexcept
Add a reference count of a buffer of sharable binary data.
void enable_reference_count_of_sharable_binary(SharableBinaryHeader *buffer) noexcept
Enable reference count of a buffer of sharable binary data.
Namespace of messages.
Definition buffer_view.h:24
Definition of SerializedMessage class.
Definition of SharableBinaryHeader struct.
Struct of headers of sharable binary data.