cpp-msgpack-light 0.3.0
A light library to serialize MessagePack.
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
27
28namespace msgpack_light {
29
33class memory_output_stream final : public output_stream {
34public:
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
78private:
80 static constexpr std::size_t initial_buffer_size = 4096U;
81
83
86};
87
88} // namespace msgpack_light
Definition of binary class.
Class of binary data.
Definition binary.h:129
std::size_t size() const noexcept
Get the size of the written data.
const binary & as_binary() const
Get the data as msgpack_light::binary instance.
const unsigned char * data() const noexcept
Get the pointer to the written data.
static constexpr std::size_t initial_buffer_size
Size of the initial buffer.
void write(const unsigned char *data, std::size_t size) override
Write data.
output_stream()=default
Constructor.
constexpr std::size_t static_memory_buffer_size
Size of buffers on memory defined using static arrays.
Namespace of this project.
Definition binary.h:33
Definition of output_stream class.
Definition of static_memory_buffer_size constant.