Sha256: 39be2c2fa50f72d6e422f108f855fa153c3ff31f3c6066be1743669e8edc5751

Contents?: true

Size: 1.66 KB

Versions: 13

Compression:

Stored size: 1.66 KB

Contents

// Copyright (c) 2017-2022 Dr. Colin Hirsch and Daniel Frey
// Please see LICENSE for license or visit https://github.com/taocpp/PEGTL/

#ifndef TAO_PEGTL_CONTRIB_INTERNAL_ENDIAN_HPP
#define TAO_PEGTL_CONTRIB_INTERNAL_ENDIAN_HPP

#include <cstdint>
#include <cstring>

#include "../../config.hpp"

#if defined( _WIN32 ) && !defined( __MINGW32__ ) && !defined( __CYGWIN__ )
#include "endian_win.hpp"
#else
#include "endian_gcc.hpp"
#endif

namespace TAO_PEGTL_NAMESPACE::internal
{
   enum class endian
   {
#if defined( _WIN32 )
      little = 0,
      big = 1,
      native = little
#elif defined( __BYTE_ORDER__ )
      little = __ORDER_LITTLE_ENDIAN__,
      big = __ORDER_BIG_ENDIAN__,
      native = __BYTE_ORDER__
#else
#error Unknown endianness.
#endif
   };

   template< typename N >
   [[nodiscard]] N h_to_be( const N n ) noexcept
   {
      return N( to_and_from_be< sizeof( N ) >::convert( n ) );
   }

   template< typename N >
   [[nodiscard]] N be_to_h( const N n ) noexcept
   {
      return h_to_be( n );
   }

   template< typename N >
   [[nodiscard]] N be_to_h( const void* p ) noexcept
   {
      N n;
      std::memcpy( &n, p, sizeof( n ) );
      return internal::be_to_h( n );
   }

   template< typename N >
   [[nodiscard]] N h_to_le( const N n ) noexcept
   {
      return N( to_and_from_le< sizeof( N ) >::convert( n ) );
   }

   template< typename N >
   [[nodiscard]] N le_to_h( const N n ) noexcept
   {
      return h_to_le( n );
   }

   template< typename N >
   [[nodiscard]] N le_to_h( const void* p ) noexcept
   {
      N n;
      std::memcpy( &n, p, sizeof( n ) );
      return internal::le_to_h( n );
   }

}  // namespace TAO_PEGTL_NAMESPACE::internal

#endif

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
couchbase-3.5.6 ext/cache/json/4c7c23ac69aa1d72b3a9295ac9aceac10d32d9a1/json/external/PEGTL/include/tao/pegtl/contrib/internal/endian.hpp
couchbase-3.5.5 ext/cache/json/4c7c23ac69aa1d72b3a9295ac9aceac10d32d9a1/json/external/PEGTL/include/tao/pegtl/contrib/internal/endian.hpp
couchbase-3.5.4 ext/cache/json/4c7c23ac69aa1d72b3a9295ac9aceac10d32d9a1/json/external/PEGTL/include/tao/pegtl/contrib/internal/endian.hpp
couchbase-3.5.3 ext/cache/json/4c7c23ac69aa1d72b3a9295ac9aceac10d32d9a1/json/external/PEGTL/include/tao/pegtl/contrib/internal/endian.hpp
couchbase-3.5.2 ext/cache/json/4c7c23ac69aa1d72b3a9295ac9aceac10d32d9a1/json/external/PEGTL/include/tao/pegtl/contrib/internal/endian.hpp
couchbase-3.5.1 ext/cache/json/4c7c23ac69aa1d72b3a9295ac9aceac10d32d9a1/json/external/PEGTL/include/tao/pegtl/contrib/internal/endian.hpp
couchbase-3.5.0 ext/cache/json/4c7c23ac69aa1d72b3a9295ac9aceac10d32d9a1/json/external/PEGTL/include/tao/pegtl/contrib/internal/endian.hpp
couchbase-3.4.5 ext/couchbase/third_party/json/external/PEGTL/include/tao/pegtl/contrib/internal/endian.hpp
couchbase-3.4.4 ext/couchbase/third_party/json/external/PEGTL/include/tao/pegtl/contrib/internal/endian.hpp
couchbase-3.4.3 ext/couchbase/third_party/json/external/PEGTL/include/tao/pegtl/contrib/internal/endian.hpp
couchbase-3.4.2 ext/couchbase/third_party/json/external/PEGTL/include/tao/pegtl/contrib/internal/endian.hpp
couchbase-3.4.1 ext/couchbase/third_party/json/external/PEGTL/include/tao/pegtl/contrib/internal/endian.hpp
couchbase-3.4.0 ext/couchbase/third_party/json/external/PEGTL/include/tao/pegtl/contrib/internal/endian.hpp