/* endian64.h
****************************************************************************************************************
****************************************************************************************************************

    Copyright (C) 2021 Askar Almatov

    This file is part of Trafficmeter.

    Trafficmeter is free software: you can redistribute it and/or modify it under the terms of the GNU General
    Public License as published by the Free Software Foundation, either version 3 of the License, or (at your
    option) any later version.

    Trafficmeter is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
    implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
    License for more details.

    You should have received a copy of the GNU General Public License along with Trafficmeter. If not, see
    <http://www.gnu.org/licenses/>.
*/

#ifndef __ENDIAN64_H
#define __ENDIAN64_H 1

#include "config.h"

#if defined( HAVE_ENDIAN_H )
#include <endian.h>
#elif defined( HAVE_SYS_ENDIAN_H )
#include <sys/endian.h>
#else
#include <libkern/OSByteOrder.h>

namespace trafficmeter
{
    inline constexpr uint64_t   htobe64( uint64_t x )   { return OSSwapHostToBigInt64(x); }
    inline constexpr uint64_t   htole64( uint64_t x )   { return OSSwapHostToLittleInt64(x); }
    inline constexpr uint64_t   be64toh( uint64_t x )   { return OSSwapBigToHostInt64(x); }
    inline constexpr uint64_t   le64toh( uint64_t x )   { return OSSwapLittleToHostInt64(x); }
}

#endif

#endif  // __ENDIAN64_H
