1 // 2 // Copyright 2010-2011 Ettus Research LLC 3 // Copyright 2018 Ettus Research, a National Instruments Company 4 // 5 // SPDX-License-Identifier: GPL-3.0-or-later 6 // 7 8 #pragma once 9 10 #include <uhd/config.hpp> 11 #include <uhd/types/endianness.hpp> 12 #include <stdint.h> 13 14 /*! \file byteswap.hpp 15 * 16 * Provide fast byteswaping routines for 16, 32, and 64 bit integers, 17 * by using the system's native routines/intrinsics when available. 18 */ 19 namespace uhd { 20 21 //! perform a byteswap on a 16 bit integer 22 uint16_t byteswap(uint16_t); 23 24 //! perform a byteswap on a 32 bit integer 25 uint32_t byteswap(uint32_t); 26 27 //! perform a byteswap on a 64 bit integer 28 uint64_t byteswap(uint64_t); 29 30 //! network to host: short, long, or long-long 31 template <typename T> 32 T ntohx(T); 33 34 //! host to network: short, long, or long-long 35 template <typename T> 36 T htonx(T); 37 38 //! worknet to host: short, long, or long-long 39 // 40 // The argument is assumed to be little-endian (i.e, the inverse 41 // of typical network endianness). 42 template <typename T> 43 T wtohx(T); 44 45 //! host to worknet: short, long, or long-long 46 // 47 // The return value is little-endian (i.e, the inverse 48 // of typical network endianness). 49 template <typename T> 50 T htowx(T); 51 52 } // namespace uhd 53 54 #include <uhd/utils/byteswap.ipp> 55