Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 08:33:51

0001 //
0002 // Copyright (c) 2019-2024 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_FRAME_HEADER_HPP
0009 #define BOOST_MYSQL_IMPL_INTERNAL_PROTOCOL_FRAME_HEADER_HPP
0010 
0011 #include <boost/assert.hpp>
0012 #include <boost/config.hpp>
0013 #include <boost/core/span.hpp>
0014 #include <boost/endian/conversion.hpp>
0015 
0016 #include <cstddef>
0017 
0018 namespace boost {
0019 namespace mysql {
0020 namespace detail {
0021 
0022 BOOST_INLINE_CONSTEXPR std::size_t max_packet_size = 0xffffff;
0023 BOOST_INLINE_CONSTEXPR std::size_t frame_header_size = 4;
0024 
0025 struct frame_header
0026 {
0027     std::uint32_t size;
0028     std::uint8_t sequence_number;
0029 };
0030 
0031 inline void serialize_frame_header(span<std::uint8_t, frame_header_size> to, frame_header header)
0032 {
0033     BOOST_ASSERT(header.size <= 0xffffff);
0034     endian::store_little_u24(to.data(), header.size);
0035     to[3] = header.sequence_number;
0036 }
0037 
0038 inline frame_header deserialize_frame_header(span<const std::uint8_t, frame_header_size> buffer)
0039 {
0040     return {endian::load_little_u24(buffer.data()), buffer[3]};
0041 }
0042 
0043 }  // namespace detail
0044 }  // namespace mysql
0045 }  // namespace boost
0046 
0047 #endif