Coverage Report

Created: 2024-07-27 06:53

/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
// Must be included last.
18
#include "google/protobuf/port_def.inc"
19
20
namespace google {
21
namespace protobuf {
22
namespace internal {
23
24
0
inline uint64_t BSwap64(uint64_t host_int) {
25
0
#if defined(PROTOBUF_BUILTIN_BSWAP64)
26
0
  return PROTOBUF_BUILTIN_BSWAP64(host_int);
27
0
#elif defined(_MSC_VER)
28
0
  return _byteswap_uint64(host_int);
29
0
#else
30
0
  return (((host_int & uint64_t{0xFF}) << 56) |
31
0
          ((host_int & uint64_t{0xFF00}) << 40) |
32
0
          ((host_int & uint64_t{0xFF0000}) << 24) |
33
0
          ((host_int & uint64_t{0xFF000000}) << 8) |
34
0
          ((host_int & uint64_t{0xFF00000000}) >> 8) |
35
0
          ((host_int & uint64_t{0xFF0000000000}) >> 24) |
36
0
          ((host_int & uint64_t{0xFF000000000000}) >> 40) |
37
0
          ((host_int & uint64_t{0xFF00000000000000}) >> 56));
38
0
#endif
39
0
}
40
41
0
inline uint32_t BSwap32(uint32_t host_int) {
42
0
#if defined(PROTOBUF_BUILTIN_BSWAP32)
43
0
  return PROTOBUF_BUILTIN_BSWAP32(host_int);
44
0
#elif defined(_MSC_VER)
45
0
  return _byteswap_ulong(host_int);
46
0
#else
47
0
  return (((host_int & uint32_t{0xFF}) << 24) |
48
0
          ((host_int & uint32_t{0xFF00}) << 8) |
49
0
          ((host_int & uint32_t{0xFF0000}) >> 8) |
50
0
          ((host_int & uint32_t{0xFF000000}) >> 24));
51
0
#endif
52
0
}
53
54
0
inline uint16_t BSwap16(uint16_t host_int) {
55
0
#if defined(PROTOBUF_BUILTIN_BSWAP16)
56
0
  return PROTOBUF_BUILTIN_BSWAP16(host_int);
57
0
#elif defined(_MSC_VER)
58
0
  return _byteswap_ushort(host_int);
59
0
#else
60
0
  return (((host_int & uint16_t{0xFF}) << 8) |
61
0
          ((host_int & uint16_t{0xFF00}) >> 8));
62
0
#endif
63
0
}
64
65
namespace little_endian {
66
67
0
inline uint16_t FromHost(uint16_t value) {
68
0
#if defined(ABSL_IS_BIG_ENDIAN)
69
0
  return BSwap16(value);
70
0
#else
71
0
  return value;
72
0
#endif
73
0
}
74
75
0
inline uint32_t FromHost(uint32_t value) {
76
0
#if defined(ABSL_IS_BIG_ENDIAN)
77
0
  return BSwap32(value);
78
0
#else
79
0
  return value;
80
0
#endif
81
0
}
82
83
0
inline uint64_t FromHost(uint64_t value) {
84
0
#if defined(ABSL_IS_BIG_ENDIAN)
85
0
  return BSwap64(value);
86
0
#else
87
0
  return value;
88
0
#endif
89
0
}
90
91
0
inline uint16_t ToHost(uint16_t value) {
92
0
#if defined(ABSL_IS_BIG_ENDIAN)
93
0
  return BSwap16(value);
94
0
#else
95
0
  return value;
96
0
#endif
97
0
}
98
99
0
inline uint32_t ToHost(uint32_t value) {
100
0
#if defined(ABSL_IS_BIG_ENDIAN)
101
0
  return BSwap32(value);
102
0
#else
103
0
  return value;
104
0
#endif
105
0
}
106
107
0
inline uint64_t ToHost(uint64_t value) {
108
0
#if defined(ABSL_IS_BIG_ENDIAN)
109
0
  return BSwap64(value);
110
0
#else
111
0
  return value;
112
0
#endif
113
0
}
114
115
}  // namespace little_endian
116
117
namespace big_endian {
118
119
0
inline uint16_t FromHost(uint16_t value) {
120
0
#if defined(ABSL_IS_BIG_ENDIAN)
121
0
  return value;
122
0
#else
123
0
  return BSwap16(value);
124
0
#endif
125
0
}
126
127
0
inline uint32_t FromHost(uint32_t value) {
128
0
#if defined(ABSL_IS_BIG_ENDIAN)
129
0
  return value;
130
0
#else
131
0
  return BSwap32(value);
132
0
#endif
133
0
}
134
135
0
inline uint64_t FromHost(uint64_t value) {
136
0
#if defined(ABSL_IS_BIG_ENDIAN)
137
0
  return value;
138
0
#else
139
0
  return BSwap64(value);
140
0
#endif
141
0
}
142
143
0
inline uint16_t ToHost(uint16_t value) {
144
0
#if defined(ABSL_IS_BIG_ENDIAN)
145
0
  return value;
146
0
#else
147
0
  return BSwap16(value);
148
0
#endif
149
0
}
150
151
0
inline uint32_t ToHost(uint32_t value) {
152
0
#if defined(ABSL_IS_BIG_ENDIAN)
153
0
  return value;
154
0
#else
155
0
  return BSwap32(value);
156
0
#endif
157
0
}
158
159
0
inline uint64_t ToHost(uint64_t value) {
160
0
#if defined(ABSL_IS_BIG_ENDIAN)
161
0
  return value;
162
0
#else
163
0
  return BSwap64(value);
164
0
#endif
165
0
}
166
167
}  // namespace big_endian
168
169
}  // namespace internal
170
}  // namespace protobuf
171
}  // namespace google
172
173
#include "google/protobuf/port_undef.inc"
174
175
#endif  // GOOGLE_PROTOBUF_ENDIAN_H__