cpp-msgpack-light
0.3.0
A light library to serialize MessagePack.
Toggle main menu visibility
Loading...
Searching...
No Matches
non_buffered_serialization_buffer_impl.h
Go to the documentation of this file.
1
/*
2
* Copyright 2024 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 <array>
23
#include <cstddef>
// IWYU pragma: keep
24
25
#include "
msgpack_light/details/mutable_static_binary_view.h
"
26
#include "
msgpack_light/details/pack_in_big_endian.h
"
27
#include "
msgpack_light/details/total_size_of.h
"
// IWYU pragma: keep
28
#include "
msgpack_light/output_stream.h
"
29
30
namespace
msgpack_light::details
{
31
36
class
non_buffered_serialization_buffer_impl
{
37
public
:
45
explicit
non_buffered_serialization_buffer_impl
(
output_stream
& stream)
46
:
stream_
(stream) {}
47
48
non_buffered_serialization_buffer_impl
(
49
const
non_buffered_serialization_buffer_impl
&) =
delete
;
50
non_buffered_serialization_buffer_impl
(
51
non_buffered_serialization_buffer_impl
&&) =
delete
;
52
non_buffered_serialization_buffer_impl
& operator=(
53
const
non_buffered_serialization_buffer_impl
&) =
delete
;
54
non_buffered_serialization_buffer_impl
& operator=(
55
non_buffered_serialization_buffer_impl
&&) =
delete
;
56
60
~non_buffered_serialization_buffer_impl
() noexcept {
flush
(); }
61
65
void
flush
() {
66
// No operation.
67
}
68
75
void
write
(
const
unsigned
char
* data, std::size_t size) {
76
stream_
.
write
(data, size);
77
}
78
84
void
put
(
unsigned
char
data) {
write
(&data, 1U); }
85
92
template
<
typename
... T>
93
void
write_in_big_endian
(T... values) {
94
std::array<
unsigned
char,
total_size_of
<T...>> buffer{};
95
pack_in_big_endian
(
96
mutable_static_binary_view
<
total_size_of<T...>
>(buffer.data()),
97
values...);
98
write
(buffer.data(), buffer.size());
99
}
100
101
private
:
103
output_stream
&
stream_
;
104
};
105
106
}
// namespace msgpack_light::details
msgpack_light::details::mutable_static_binary_view
Class of views of mutable buffers with static sizes.
Definition
mutable_static_binary_view.h:32
msgpack_light::details::non_buffered_serialization_buffer_impl
Class to implement internal implementation of serialization_buffer class without buffers.
Definition
non_buffered_serialization_buffer_impl.h:36
msgpack_light::details::non_buffered_serialization_buffer_impl::stream_
output_stream & stream_
Stream to write output to.
Definition
non_buffered_serialization_buffer_impl.h:103
msgpack_light::details::non_buffered_serialization_buffer_impl::non_buffered_serialization_buffer_impl
non_buffered_serialization_buffer_impl(output_stream &stream)
Constructor.
Definition
non_buffered_serialization_buffer_impl.h:45
msgpack_light::details::non_buffered_serialization_buffer_impl::flush
void flush()
Flush the internal buffer in this instance.
Definition
non_buffered_serialization_buffer_impl.h:65
msgpack_light::details::non_buffered_serialization_buffer_impl::write_in_big_endian
void write_in_big_endian(T... values)
Write values in big endian.
Definition
non_buffered_serialization_buffer_impl.h:93
msgpack_light::details::non_buffered_serialization_buffer_impl::~non_buffered_serialization_buffer_impl
~non_buffered_serialization_buffer_impl() noexcept
Destructor.
Definition
non_buffered_serialization_buffer_impl.h:60
msgpack_light::details::non_buffered_serialization_buffer_impl::write
void write(const unsigned char *data, std::size_t size)
Write data.
Definition
non_buffered_serialization_buffer_impl.h:75
msgpack_light::details::non_buffered_serialization_buffer_impl::put
void put(unsigned char data)
Write a byte of data.
Definition
non_buffered_serialization_buffer_impl.h:84
msgpack_light::output_stream
Interface of streams to write data.
Definition
output_stream.h:32
msgpack_light::output_stream::write
virtual void write(const unsigned char *data, std::size_t size)=0
Write data.
mutable_static_binary_view.h
Definition of mutable_static_binary_view class.
msgpack_light::details
Namespace of internal implementations.
Definition
binary.h:35
msgpack_light::details::pack_in_big_endian
void pack_in_big_endian(mutable_static_binary_view< total_size_of< T, Remaining... > > buffer, T value, Remaining... remaining_values) noexcept
Pack some values in big endian.
Definition
pack_in_big_endian.h:38
msgpack_light::details::total_size_of
constexpr std::size_t total_size_of
Get the total size of types in template arguments.
Definition
total_size_of.h:64
output_stream.h
Definition of output_stream class.
pack_in_big_endian.h
Definition of pack_in_big_endian function.
total_size_of.h
Definition of total_size_of variable.
include
msgpack_light
details
non_buffered_serialization_buffer_impl.h
Generated on
for cpp-msgpack-light by
1.18.0