cpp-msgpack-light
0.3.0
A light library to serialize MessagePack.
Toggle main menu visibility
Loading...
Searching...
No Matches
memory_output_stream.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 <cstddef>
23
24
#include "
msgpack_light/binary.h
"
25
#include "
msgpack_light/details/static_memory_buffer_size.h
"
26
#include "
msgpack_light/output_stream.h
"
27
28
namespace
msgpack_light
{
29
33
class
memory_output_stream
final :
public
output_stream
{
34
public
:
38
memory_output_stream
() {
buffer_
.
reserve
(
initial_buffer_size
); }
39
46
void
write
(
const
unsigned
char
*
data
, std::size_t
size
)
override
{
47
buffer_
.
append
(
data
,
size
);
48
}
49
53
void
clear
() {
buffer_
.
resize
(0U); }
54
60
[[nodiscard]]
const
unsigned
char
*
data
() const noexcept {
61
return
buffer_
.
data
();
62
}
63
69
[[nodiscard]] std::size_t
size
() const noexcept {
return
buffer_
.
size
(); }
70
76
[[nodiscard]]
const
binary
&
as_binary
()
const
{
return
buffer_
; }
77
78
private
:
80
static
constexpr
std::size_t
initial_buffer_size
= 4096U;
81
82
static_assert
(
initial_buffer_size
>
details::static_memory_buffer_size
);
83
85
binary
buffer_
{};
86
};
87
88
}
// namespace msgpack_light
binary.h
Definition of binary class.
msgpack_light::binary
Class of binary data.
Definition
binary.h:129
msgpack_light::binary::reserve
void reserve(std::size_t size)
Change the size of the internal buffer.
Definition
binary.h:245
msgpack_light::binary::data
unsigned char * data() noexcept
Get the pointer to the data.
Definition
binary.h:304
msgpack_light::binary::size
std::size_t size() const noexcept
Get the size of the data.
Definition
binary.h:320
msgpack_light::binary::resize
void resize(std::size_t size)
Change the size of this data.
Definition
binary.h:231
msgpack_light::binary::append
void append(const unsigned char *data, std::size_t size)
Append another binary data.
Definition
binary.h:257
msgpack_light::memory_output_stream::size
std::size_t size() const noexcept
Get the size of the written data.
Definition
memory_output_stream.h:69
msgpack_light::memory_output_stream::buffer_
binary buffer_
Buffer.
Definition
memory_output_stream.h:85
msgpack_light::memory_output_stream::as_binary
const binary & as_binary() const
Get the data as msgpack_light::binary instance.
Definition
memory_output_stream.h:76
msgpack_light::memory_output_stream::clear
void clear()
Clear data.
Definition
memory_output_stream.h:53
msgpack_light::memory_output_stream::data
const unsigned char * data() const noexcept
Get the pointer to the written data.
Definition
memory_output_stream.h:60
msgpack_light::memory_output_stream::initial_buffer_size
static constexpr std::size_t initial_buffer_size
Size of the initial buffer.
Definition
memory_output_stream.h:80
msgpack_light::memory_output_stream::memory_output_stream
memory_output_stream()
Constructor.
Definition
memory_output_stream.h:38
msgpack_light::memory_output_stream::write
void write(const unsigned char *data, std::size_t size) override
Write data.
Definition
memory_output_stream.h:46
msgpack_light::output_stream::output_stream
output_stream()=default
Constructor.
msgpack_light::details::static_memory_buffer_size
constexpr std::size_t static_memory_buffer_size
Size of buffers on memory defined using static arrays.
Definition
static_memory_buffer_size.h:29
msgpack_light
Namespace of this project.
Definition
binary.h:33
output_stream.h
Definition of output_stream class.
static_memory_buffer_size.h
Definition of static_memory_buffer_size constant.
include
msgpack_light
memory_output_stream.h
Generated on
for cpp-msgpack-light by
1.18.0