cpp-msgpack-light 0.3.0
A light library to serialize MessagePack.
Loading...
Searching...
No Matches
pack_in_big_endian.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
24#include "msgpack_light/details/total_size_of.h" // IWYU pragma: keep
25
26namespace msgpack_light::details {
27
37template <typename T, typename... Remaining>
40 Remaining... remaining_values) noexcept {
41 if constexpr (sizeof(T) == 1U) {
42 buffer[0] = static_cast<unsigned char>(value);
43 } else {
44 if constexpr (sizeof...(Remaining) == 0U) {
45 to_big_endian(&value, buffer);
46 } else {
47 to_big_endian(&value, buffer.template sub_buffer<0U, sizeof(T)>());
48 }
49 }
50 if constexpr (sizeof...(Remaining) > 0U) {
52 buffer.template sub_buffer<sizeof(T)>(), remaining_values...);
53 }
54}
55
56} // namespace msgpack_light::details
Class of views of mutable buffers with static sizes.
Definition of mutable_static_binary_view class.
Namespace of internal implementations.
Definition binary.h:35
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.
constexpr std::size_t total_size_of
Get the total size of types in template arguments.
void to_big_endian(const void *from, mutable_static_binary_view< N > to) noexcept
Convert to big endian.
Definition of to_big_endian function.
Definition of total_size_of variable.