cpp-msgpack-light 0.3.0
A light library to serialize MessagePack.
Loading...
Searching...
No Matches
mutable_static_binary_view.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
24namespace msgpack_light::details {
25
31template <std::size_t N>
33public:
39 explicit mutable_static_binary_view(unsigned char* buffer) noexcept
40 : buffer_(buffer) {}
41
48 unsigned char& operator[](std::size_t index) noexcept {
49 return buffer_[index];
50 }
51
58 unsigned char operator[](std::size_t index) const noexcept {
59 return buffer_[index];
60 }
61
67 unsigned char* data() noexcept { return buffer_; }
68
74 [[nodiscard]] std::size_t size() const noexcept { return N; }
75
82 template <std::size_t Start, std::size_t Size = N - Start>
83 [[nodiscard]] mutable_static_binary_view<Size> sub_buffer() const noexcept {
84 static_assert(Start <= N);
85 static_assert(Start + Size <= N);
87 }
88
89private:
91 unsigned char* buffer_;
92};
93
94} // namespace msgpack_light::details
unsigned char & operator[](std::size_t index) noexcept
Access to a byte.
unsigned char operator[](std::size_t index) const noexcept
Get a byte.
std::size_t size() const noexcept
Get the size of the buffer.
unsigned char * data() noexcept
Access the buffer.
mutable_static_binary_view< Size > sub_buffer() const noexcept
Get a subset of this buffer.
mutable_static_binary_view(unsigned char *buffer) noexcept
Constructor.
Namespace of internal implementations.
Definition binary.h:35