cpp-msgpack-light 0.3.0
A light library to serialize MessagePack.
Loading...
Searching...
No Matches
serialize.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
26#include "msgpack_light/type_support/common.h" // IWYU pragma: export
27
28namespace msgpack_light {
29
37template <typename T>
38inline void serialize_to(output_stream& stream, const T& data) {
39 serialization_buffer buffer(stream);
40 buffer.serialize(data);
41 buffer.flush();
42}
43
51template <typename T>
52[[nodiscard]] inline binary serialize(const T& data) {
54 serialize_to(stream, data);
55 return stream.as_binary();
56}
57
58} // namespace msgpack_light
Definition of binary class.
Class of binary data.
Definition binary.h:129
Class of streams to write data to memory.
const binary & as_binary() const
Get the data as msgpack_light::binary instance.
Interface of streams to write data.
Class of buffers to serialize data.
void serialize(const T &data)
Serialize data.
void flush()
Flush the internal buffer in this instance.
Header to include headers to support common data types.
Definition of memory_output_stream class.
Namespace of this project.
Definition binary.h:33
void serialize_to(output_stream &stream, const T &data)
Serialize data in memory and return the resulting binary data.
Definition serialize.h:38
binary serialize(const T &data)
Serialize data to an output stream.
Definition serialize.h:52
Definition of output_stream class.
Definition of serialization_buffer class.