admin
2023-03-07 8b06b1cbf112d55307ea8a6efe711db4e7506d89
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
 
#ifndef MINI_CHROMIUM_BASE_SYS_BYTEORDER_H_
#define MINI_CHROMIUM_BASE_SYS_BYTEORDER_H_
 
#include "base/macros.h"
#include "build/build_config.h"
 
#if defined(OS_APPLE)
#include <libkern/OSByteOrder.h>
#elif defined(OS_WIN)
#include <stdlib.h>
#else
#include <byteswap.h>
#endif
 
namespace base {
 
inline uint16_t ByteSwap(uint16_t x) {
#if defined(OS_APPLE)
  return OSSwapInt16(x);
#elif defined(OS_WIN)
  return _byteswap_ushort(x);
#else
  return bswap_16(x);
#endif
}
 
inline uint32_t ByteSwap(uint32_t x) {
#if defined(OS_APPLE)
  return OSSwapInt32(x);
#elif defined(OS_WIN)
  return _byteswap_ulong(x);
#else
  return bswap_32(x);
#endif
}
 
inline uint64_t ByteSwap(uint64_t x) {
#if defined(OS_APPLE)
  return OSSwapInt64(x);
#elif defined(OS_WIN)
  return _byteswap_uint64(x);
#else
  return bswap_64(x);
#endif
}
 
inline uint16_t NetToHost16(uint16_t x) {
#if defined(ARCH_CPU_LITTLE_ENDIAN)
  return ByteSwap(x);
#else
  return x;
#endif
}
 
inline uint32_t NetToHost32(uint32_t x) {
#if defined(ARCH_CPU_LITTLE_ENDIAN)
  return ByteSwap(x);
#else
  return x;
#endif
}
 
inline uint64_t NetToHost64(uint64_t x) {
#if defined(ARCH_CPU_LITTLE_ENDIAN)
  return ByteSwap(x);
#else
  return x;
#endif
}
 
inline uint16_t HostToNet16(uint16_t x) {
#if defined(ARCH_CPU_LITTLE_ENDIAN)
  return ByteSwap(x);
#else
  return x;
#endif
}
 
inline uint32_t HostToNet32(uint32_t x) {
#if defined(ARCH_CPU_LITTLE_ENDIAN)
  return ByteSwap(x);
#else
  return x;
#endif
}
 
inline uint64_t HostToNet64(uint64_t x) {
#if defined(ARCH_CPU_LITTLE_ENDIAN)
  return ByteSwap(x);
#else
  return x;
#endif
}
 
}  // namespace base
 
#endif  // MINI_CHROMIUM_BASE_SYS_BYTEORDER_H_