Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:42:42

0001 //
0002 // Copyright (c) 2019-2023 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_MYSQL_IMPL_INTERNAL_PROTOCOL_STATIC_BUFFER_HPP
0009 #define BOOST_MYSQL_IMPL_INTERNAL_PROTOCOL_STATIC_BUFFER_HPP
0010 
0011 // A very simplified variable-length buffer with fixed max-size
0012 
0013 #include <boost/assert.hpp>
0014 #include <boost/core/span.hpp>
0015 
0016 #include <array>
0017 #include <cstring>
0018 
0019 namespace boost {
0020 namespace mysql {
0021 namespace detail {
0022 
0023 template <std::size_t max_size>
0024 class static_buffer
0025 {
0026     std::array<std::uint8_t, max_size> buffer_{};
0027     std::size_t size_{};
0028 
0029 public:
0030     static_buffer() noexcept = default;
0031     span<const std::uint8_t> to_span() const noexcept { return {buffer_.data(), size_}; }
0032     void append(const void* data, std::size_t data_size) noexcept
0033     {
0034         std::size_t new_size = size_ + data_size;
0035         BOOST_ASSERT(new_size <= max_size);
0036         std::memcpy(buffer_.data() + size_, data, data_size);
0037         size_ = new_size;
0038     }
0039     void clear() noexcept { size_ = 0; }
0040 };
0041 
0042 }  // namespace detail
0043 }  // namespace mysql
0044 }  // namespace boost
0045 
0046 #endif