Back to home page

EIC code displayed by LXR

 
 

    


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

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_BIT_DESERIALIZATION_HPP
0009 #define BOOST_MYSQL_IMPL_INTERNAL_PROTOCOL_BIT_DESERIALIZATION_HPP
0010 
0011 #include <boost/mysql/field_view.hpp>
0012 #include <boost/mysql/string_view.hpp>
0013 
0014 #include <boost/mysql/impl/internal/protocol/serialization.hpp>
0015 
0016 #include <boost/endian/conversion.hpp>
0017 
0018 #include <cstring>
0019 
0020 namespace boost {
0021 namespace mysql {
0022 namespace detail {
0023 
0024 // All BIT values come as binary values between 1 and 8 bytes length packed in string_lenenc's,
0025 // for both the text and the binary protocols. As the text protocol already unpacks the
0026 // string_lenenc layer, this function is in charge of just parsing the binary payload. The length of
0027 // the BIT value depends on how the type was defined in the table (e.g. BIT(14) will send a 2 byte
0028 // value; BIT(54) will send a 7 byte one). Values are sent as big-endian.
0029 inline deserialize_errc deserialize_bit(string_view from, field_view& to) noexcept
0030 {
0031     std::size_t num_bytes = from.size();
0032     if (num_bytes < 1 || num_bytes > 8)
0033     {
0034         return deserialize_errc::protocol_value_error;
0035     }
0036     unsigned char temp[8]{};
0037     unsigned char* dest = temp + sizeof(temp) - num_bytes;
0038     std::memcpy(dest, from.data(), num_bytes);
0039     to = field_view(endian::load_big_u64(temp));
0040     return deserialize_errc::ok;
0041 }
0042 
0043 }  // namespace detail
0044 }  // namespace mysql
0045 }  // namespace boost
0046 
0047 #endif