cpp-msgpack-light
0.3.0
A light library to serialize MessagePack.
Toggle main menu visibility
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
24
namespace
msgpack_light::details
{
25
31
template
<std::
size_t
N>
32
class
mutable_static_binary_view
{
33
public
:
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);
86
return
mutable_static_binary_view<Size>
(
buffer_
+ Start);
87
}
88
89
private
:
91
unsigned
char
*
buffer_
;
92
};
93
94
}
// namespace msgpack_light::details
msgpack_light::details::mutable_static_binary_view::operator[]
unsigned char & operator[](std::size_t index) noexcept
Access to a byte.
Definition
mutable_static_binary_view.h:48
msgpack_light::details::mutable_static_binary_view::operator[]
unsigned char operator[](std::size_t index) const noexcept
Get a byte.
Definition
mutable_static_binary_view.h:58
msgpack_light::details::mutable_static_binary_view::size
std::size_t size() const noexcept
Get the size of the buffer.
Definition
mutable_static_binary_view.h:74
msgpack_light::details::mutable_static_binary_view::data
unsigned char * data() noexcept
Access the buffer.
Definition
mutable_static_binary_view.h:67
msgpack_light::details::mutable_static_binary_view::sub_buffer
mutable_static_binary_view< Size > sub_buffer() const noexcept
Get a subset of this buffer.
Definition
mutable_static_binary_view.h:83
msgpack_light::details::mutable_static_binary_view::buffer_
unsigned char * buffer_
Buffer.
Definition
mutable_static_binary_view.h:91
msgpack_light::details::mutable_static_binary_view::mutable_static_binary_view
mutable_static_binary_view(unsigned char *buffer) noexcept
Constructor.
Definition
mutable_static_binary_view.h:39
msgpack_light::details
Namespace of internal implementations.
Definition
binary.h:35
include
msgpack_light
details
mutable_static_binary_view.h
Generated on
for cpp-msgpack-light by
1.18.0