Coverage Report

Created: 2025-04-27 06:20

/src/LPM/external.protobuf/include/google/protobuf/endian.h
Line
Count
Source (jump to first uncovered line)
1
// Protocol Buffers - Google's data interchange format
2
// Copyright 2008 Google Inc.  All rights reserved.
3
//
4
// Use of this source code is governed by a BSD-style
5
// license that can be found in the LICENSE file or at
6
// https://developers.google.com/open-source/licenses/bsd
7
8
#ifndef GOOGLE_PROTOBUF_ENDIAN_H__
9
#define GOOGLE_PROTOBUF_ENDIAN_H__
10
11
#if defined(_MSC_VER)
12
#include <stdlib.h>
13
#endif
14
15
#include <cstdint>
16
17
#include "absl/base/config.h"
18
19
// Must be included last.
20
#include "google/protobuf/port_def.inc"
21
22
namespace google {
23
namespace protobuf {
24
namespace internal {
25
26
0
inline uint64_t BSwap64(uint64_t host_int) {
27
0
#if defined(__GNUC__) || ABSL_HAVE_BUILTIN(__builtin_bswap64)
28
0
  return __builtin_bswap64(host_int);
29
0
#elif defined(_MSC_VER)
30
0
  return _byteswap_uint64(host_int);
31
0
#else
32
0
  return (((host_int & uint64_t{0xFF}) << 56) |
33
0
          ((host_int & uint64_t{0xFF00}) << 40) |
34
0
          ((host_int & uint64_t{0xFF0000}) << 24) |
35
0
          ((host_int & uint64_t{0xFF000000}) << 8) |
36
0
          ((host_int & uint64_t{0xFF00000000}) >> 8) |
37
0
          ((host_int & uint64_t{0xFF0000000000}) >> 24) |
38
0
          ((host_int & uint64_t{0xFF000000000000}) >> 40) |
39
0
          ((host_int & uint64_t{0xFF00000000000000}) >> 56));
40
0
#endif
41
0
}
42
43
0
inline uint32_t BSwap32(uint32_t host_int) {
44
0
#if defined(__GNUC__) || ABSL_HAVE_BUILTIN(__builtin_bswap32)
45
0
  return __builtin_bswap32(host_int);
46
0
#elif defined(_MSC_VER)
47
0
  return _byteswap_ulong(host_int);
48
0
#else
49
0
  return (((host_int & uint32_t{0xFF}) << 24) |
50
0
          ((host_int & uint32_t{0xFF00}) << 8) |
51
0
          ((host_int & uint32_t{0xFF0000}) >> 8) |
52
0
          ((host_int & uint32_t{0xFF000000}) >> 24));
53
0
#endif
54
0
}
55
56
0
inline uint16_t BSwap16(uint16_t host_int) {
57
0
#if defined(__GNUC__) || ABSL_HAVE_BUILTIN(__builtin_bswap16)
58
0
  return __builtin_bswap16(host_int);
59
0
#elif defined(_MSC_VER)
60
0
  return _byteswap_ushort(host_int);
61
0
#else
62
0
  return (((host_int & uint16_t{0xFF}) << 8) |
63
0
          ((host_int & uint16_t{0xFF00}) >> 8));
64
0
#endif
65
0
}
66
67
namespace little_endian {
68
69
0
inline uint16_t FromHost(uint16_t value) {
70
0
#if defined(ABSL_IS_BIG_ENDIAN)
71
0
  return BSwap16(value);
72
0
#else
73
0
  return value;
74
0
#endif
75
0
}
76
77
0
inline uint32_t FromHost(uint32_t value) {
78
0
#if defined(ABSL_IS_BIG_ENDIAN)
79
0
  return BSwap32(value);
80
0
#else
81
0
  return value;
82
0
#endif
83
0
}
84
85
0
inline uint64_t FromHost(uint64_t value) {
86
0
#if defined(ABSL_IS_BIG_ENDIAN)
87
0
  return BSwap64(value);
88
0
#else
89
0
  return value;
90
0
#endif
91
0
}
92
93
0
inline uint16_t ToHost(uint16_t value) {
94
0
#if defined(ABSL_IS_BIG_ENDIAN)
95
0
  return BSwap16(value);
96
0
#else
97
0
  return value;
98
0
#endif
99
0
}
100
101
0
inline uint32_t ToHost(uint32_t value) {
102
0
#if defined(ABSL_IS_BIG_ENDIAN)
103
0
  return BSwap32(value);
104
0
#else
105
0
  return value;
106
0
#endif
107
0
}
108
109
0
inline uint64_t ToHost(uint64_t value) {
110
0
#if defined(ABSL_IS_BIG_ENDIAN)
111
0
  return BSwap64(value);
112
0
#else
113
0
  return value;
114
0
#endif
115
0
}
116
117
}  // namespace little_endian
118
119
namespace big_endian {
120
121
0
inline uint16_t FromHost(uint16_t value) {
122
0
#if defined(ABSL_IS_BIG_ENDIAN)
123
0
  return value;
124
0
#else
125
0
  return BSwap16(value);
126
0
#endif
127
0
}
128
129
0
inline uint32_t FromHost(uint32_t value) {
130
0
#if defined(ABSL_IS_BIG_ENDIAN)
131
0
  return value;
132
0
#else
133
0
  return BSwap32(value);
134
0
#endif
135
0
}
136
137
0
inline uint64_t FromHost(uint64_t value) {
138
0
#if defined(ABSL_IS_BIG_ENDIAN)
139
0
  return value;
140
0
#else
141
0
  return BSwap64(value);
142
0
#endif
143
0
}
144
145
0
inline uint16_t ToHost(uint16_t value) {
146
0
#if defined(ABSL_IS_BIG_ENDIAN)
147
0
  return value;
148
0
#else
149
0
  return BSwap16(value);
150
0
#endif
151
0
}
152
153
0
inline uint32_t ToHost(uint32_t value) {
154
0
#if defined(ABSL_IS_BIG_ENDIAN)
155
0
  return value;
156
0
#else
157
0
  return BSwap32(value);
158
0
#endif
159
0
}
160
161
0
inline uint64_t ToHost(uint64_t value) {
162
0
#if defined(ABSL_IS_BIG_ENDIAN)
163
0
  return value;
164
0
#else
165
0
  return BSwap64(value);
166
0
#endif
167
0
}
168
169
}  // namespace big_endian
170
171
}  // namespace internal
172
}  // namespace protobuf
173
}  // namespace google
174
175
#include "google/protobuf/port_undef.inc"
176
177
#endif  // GOOGLE_PROTOBUF_ENDIAN_H__