blob: b6c7a6420ed9b560f9383aac6af3d72efface6ce [file] [log] [blame]
kumarashishg826308d2023-06-23 13:21:22 +00001// Copyright 2019 The PDFium Authors
Haibo Huang49cc9302020-04-27 16:14:24 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CORE_FXCRT_BYTEORDER_H_
6#define CORE_FXCRT_BYTEORDER_H_
7
8#include "build/build_config.h"
9#include "third_party/base/sys_byteorder.h"
10
11namespace fxcrt {
12
13// Converts the bytes in |x| from host order (endianness) to little endian, and
14// returns the result.
15inline uint16_t ByteSwapToLE16(uint16_t x) {
16 return pdfium::base::ByteSwapToLE16(x);
17}
18
19inline uint32_t ByteSwapToLE32(uint32_t x) {
20 return pdfium::base::ByteSwapToLE32(x);
21}
22
23// Converts the bytes in |x| from host order (endianness) to big endian, and
24// returns the result.
25inline uint16_t ByteSwapToBE16(uint16_t x) {
26#if defined(ARCH_CPU_LITTLE_ENDIAN)
27 return pdfium::base::ByteSwap(x);
28#else
29 return x;
30#endif
31}
32
33inline uint32_t ByteSwapToBE32(uint32_t x) {
34#if defined(ARCH_CPU_LITTLE_ENDIAN)
35 return pdfium::base::ByteSwap(x);
36#else
37 return x;
38#endif
39}
40
41} // namespace fxcrt
42
43#endif // CORE_FXCRT_BYTEORDER_H_