aboutsummaryrefslogtreecommitdiff
path: root/core/fxcrt/byteorder.h
blob: b6c7a6420ed9b560f9383aac6af3d72efface6ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2019 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CORE_FXCRT_BYTEORDER_H_
#define CORE_FXCRT_BYTEORDER_H_

#include "build/build_config.h"
#include "third_party/base/sys_byteorder.h"

namespace fxcrt {

// Converts the bytes in |x| from host order (endianness) to little endian, and
// returns the result.
inline uint16_t ByteSwapToLE16(uint16_t x) {
  return pdfium::base::ByteSwapToLE16(x);
}

inline uint32_t ByteSwapToLE32(uint32_t x) {
  return pdfium::base::ByteSwapToLE32(x);
}

// Converts the bytes in |x| from host order (endianness) to big endian, and
// returns the result.
inline uint16_t ByteSwapToBE16(uint16_t x) {
#if defined(ARCH_CPU_LITTLE_ENDIAN)
  return pdfium::base::ByteSwap(x);
#else
  return x;
#endif
}

inline uint32_t ByteSwapToBE32(uint32_t x) {
#if defined(ARCH_CPU_LITTLE_ENDIAN)
  return pdfium::base::ByteSwap(x);
#else
  return x;
#endif
}

}  // namespace fxcrt

#endif  // CORE_FXCRT_BYTEORDER_H_