/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 | | // https://developers.google.com/protocol-buffers/ |
4 | | // |
5 | | // Redistribution and use in source and binary forms, with or without |
6 | | // modification, are permitted provided that the following conditions are |
7 | | // met: |
8 | | // |
9 | | // * Redistributions of source code must retain the above copyright |
10 | | // notice, this list of conditions and the following disclaimer. |
11 | | // * Redistributions in binary form must reproduce the above |
12 | | // copyright notice, this list of conditions and the following disclaimer |
13 | | // in the documentation and/or other materials provided with the |
14 | | // distribution. |
15 | | // * Neither the name of Google Inc. nor the names of its |
16 | | // contributors may be used to endorse or promote products derived from |
17 | | // this software without specific prior written permission. |
18 | | // |
19 | | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
20 | | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
21 | | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
22 | | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
23 | | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
24 | | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
25 | | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26 | | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 | | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 | | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 | | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | | |
31 | | #ifndef GOOGLE_PROTOBUF_ENDIAN_H__ |
32 | | #define GOOGLE_PROTOBUF_ENDIAN_H__ |
33 | | |
34 | | #if defined(_MSC_VER) |
35 | | #include <stdlib.h> |
36 | | #endif |
37 | | |
38 | | #include <cstdint> |
39 | | |
40 | | // Must be included last. |
41 | | #include "google/protobuf/port_def.inc" |
42 | | |
43 | | namespace google { |
44 | | namespace protobuf { |
45 | | namespace internal { |
46 | | |
47 | 0 | inline uint64_t BSwap64(uint64_t host_int) { |
48 | 0 | #if defined(PROTOBUF_BUILTIN_BSWAP64) |
49 | 0 | return PROTOBUF_BUILTIN_BSWAP64(host_int); |
50 | 0 | #elif defined(_MSC_VER) |
51 | 0 | return _byteswap_uint64(host_int); |
52 | 0 | #else |
53 | 0 | return (((host_int & uint64_t{0xFF}) << 56) | |
54 | 0 | ((host_int & uint64_t{0xFF00}) << 40) | |
55 | 0 | ((host_int & uint64_t{0xFF0000}) << 24) | |
56 | 0 | ((host_int & uint64_t{0xFF000000}) << 8) | |
57 | 0 | ((host_int & uint64_t{0xFF00000000}) >> 8) | |
58 | 0 | ((host_int & uint64_t{0xFF0000000000}) >> 24) | |
59 | 0 | ((host_int & uint64_t{0xFF000000000000}) >> 40) | |
60 | 0 | ((host_int & uint64_t{0xFF00000000000000}) >> 56)); |
61 | 0 | #endif |
62 | 0 | } |
63 | | |
64 | 0 | inline uint32_t BSwap32(uint32_t host_int) { |
65 | 0 | #if defined(PROTOBUF_BUILTIN_BSWAP32) |
66 | 0 | return PROTOBUF_BUILTIN_BSWAP32(host_int); |
67 | 0 | #elif defined(_MSC_VER) |
68 | 0 | return _byteswap_ulong(host_int); |
69 | 0 | #else |
70 | 0 | return (((host_int & uint32_t{0xFF}) << 24) | |
71 | 0 | ((host_int & uint32_t{0xFF00}) << 8) | |
72 | 0 | ((host_int & uint32_t{0xFF0000}) >> 8) | |
73 | 0 | ((host_int & uint32_t{0xFF000000}) >> 24)); |
74 | 0 | #endif |
75 | 0 | } |
76 | | |
77 | 0 | inline uint16_t BSwap16(uint16_t host_int) { |
78 | 0 | #if defined(PROTOBUF_BUILTIN_BSWAP16) |
79 | 0 | return PROTOBUF_BUILTIN_BSWAP16(host_int); |
80 | 0 | #elif defined(_MSC_VER) |
81 | 0 | return _byteswap_ushort(host_int); |
82 | 0 | #else |
83 | 0 | return (((host_int & uint16_t{0xFF}) << 8) | |
84 | 0 | ((host_int & uint16_t{0xFF00}) >> 8)); |
85 | 0 | #endif |
86 | 0 | } |
87 | | |
88 | | namespace little_endian { |
89 | | |
90 | 0 | inline uint16_t FromHost(uint16_t value) { |
91 | 0 | #if defined(PROTOBUF_BIG_ENDIAN) |
92 | 0 | return BSwap16(value); |
93 | 0 | #else |
94 | 0 | return value; |
95 | 0 | #endif |
96 | 0 | } |
97 | | |
98 | 0 | inline uint32_t FromHost(uint32_t value) { |
99 | 0 | #if defined(PROTOBUF_BIG_ENDIAN) |
100 | 0 | return BSwap32(value); |
101 | 0 | #else |
102 | 0 | return value; |
103 | 0 | #endif |
104 | 0 | } |
105 | | |
106 | 0 | inline uint64_t FromHost(uint64_t value) { |
107 | 0 | #if defined(PROTOBUF_BIG_ENDIAN) |
108 | 0 | return BSwap64(value); |
109 | 0 | #else |
110 | 0 | return value; |
111 | 0 | #endif |
112 | 0 | } |
113 | | |
114 | 0 | inline uint16_t ToHost(uint16_t value) { |
115 | 0 | #if defined(PROTOBUF_BIG_ENDIAN) |
116 | 0 | return BSwap16(value); |
117 | 0 | #else |
118 | 0 | return value; |
119 | 0 | #endif |
120 | 0 | } |
121 | | |
122 | 0 | inline uint32_t ToHost(uint32_t value) { |
123 | 0 | #if defined(PROTOBUF_BIG_ENDIAN) |
124 | 0 | return BSwap32(value); |
125 | 0 | #else |
126 | 0 | return value; |
127 | 0 | #endif |
128 | 0 | } |
129 | | |
130 | 0 | inline uint64_t ToHost(uint64_t value) { |
131 | 0 | #if defined(PROTOBUF_BIG_ENDIAN) |
132 | 0 | return BSwap64(value); |
133 | 0 | #else |
134 | 0 | return value; |
135 | 0 | #endif |
136 | 0 | } |
137 | | |
138 | | } // namespace little_endian |
139 | | |
140 | | namespace big_endian { |
141 | | |
142 | 0 | inline uint16_t FromHost(uint16_t value) { |
143 | 0 | #if defined(PROTOBUF_BIG_ENDIAN) |
144 | 0 | return value; |
145 | 0 | #else |
146 | 0 | return BSwap16(value); |
147 | 0 | #endif |
148 | 0 | } |
149 | | |
150 | 0 | inline uint32_t FromHost(uint32_t value) { |
151 | 0 | #if defined(PROTOBUF_BIG_ENDIAN) |
152 | 0 | return value; |
153 | 0 | #else |
154 | 0 | return BSwap32(value); |
155 | 0 | #endif |
156 | 0 | } |
157 | | |
158 | 0 | inline uint64_t FromHost(uint64_t value) { |
159 | 0 | #if defined(PROTOBUF_BIG_ENDIAN) |
160 | 0 | return value; |
161 | 0 | #else |
162 | 0 | return BSwap64(value); |
163 | 0 | #endif |
164 | 0 | } |
165 | | |
166 | 0 | inline uint16_t ToHost(uint16_t value) { |
167 | 0 | #if defined(PROTOBUF_BIG_ENDIAN) |
168 | 0 | return value; |
169 | 0 | #else |
170 | 0 | return BSwap16(value); |
171 | 0 | #endif |
172 | 0 | } |
173 | | |
174 | 0 | inline uint32_t ToHost(uint32_t value) { |
175 | 0 | #if defined(PROTOBUF_BIG_ENDIAN) |
176 | 0 | return value; |
177 | 0 | #else |
178 | 0 | return BSwap32(value); |
179 | 0 | #endif |
180 | 0 | } |
181 | | |
182 | 0 | inline uint64_t ToHost(uint64_t value) { |
183 | 0 | #if defined(PROTOBUF_BIG_ENDIAN) |
184 | 0 | return value; |
185 | 0 | #else |
186 | 0 | return BSwap64(value); |
187 | 0 | #endif |
188 | 0 | } |
189 | | |
190 | | } // namespace big_endian |
191 | | |
192 | | } // namespace internal |
193 | | } // namespace protobuf |
194 | | } // namespace google |
195 | | |
196 | | #include "google/protobuf/port_undef.inc" |
197 | | |
198 | | #endif // GOOGLE_PROTOBUF_ENDIAN_H__ |