2 * Copyright (c) 2020 nlio Authors. All Rights Reserved.
3 * Copyright 2012-2016 Nest Labs Inc. All Rights Reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 * This file defines defines functions for performing by value
21 * byte reordering for 16-, 32-, and 64-bit quantities both
22 * to-and-from the target system (i.e. host) byte ordering
23 * to-and-from both little and big endian byte ordering,
24 * specifically for big endian target systems.
27 #ifndef NLBYTEORDER_BIG_H
28 #define NLBYTEORDER_BIG_H
31 * This conditionally performs, as necessary for the target system, a
32 * byte order swap by value of the specified 16-bit value, presumed to
33 * be in little endian byte ordering to the target system (i.e. host)
36 * Consequently, on little endian target systems, this is a no-op and
37 * on big endian target systems, this performs a reordering.
39 * @param[in] inValue The 16-bit value to be byte order swapped.
41 * @return The input value, byte order swapped.
43 static inline uint16_t nlByteOrderSwap16LittleToHost(uint16_t inValue)
45 return nlByteOrderValueSwap16(inValue);
49 * This conditionally performs, as necessary for the target system, a
50 * byte order swap by value of the specified 32-bit value, presumed to
51 * be in little endian byte ordering to the target system (i.e. host)
54 * Consequently, on little endian target systems, this is a no-op and
55 * on big endian target systems, this performs a reordering.
57 * @param[in] inValue The 32-bit value to be byte order swapped.
59 * @return The input value, byte order swapped.
61 static inline uint32_t nlByteOrderSwap32LittleToHost(uint32_t inValue)
63 return nlByteOrderValueSwap32(inValue);
67 * This conditionally performs, as necessary for the target system, a
68 * byte order swap by value of the specified 64-bit value, presumed to
69 * be in little endian byte ordering to the target system (i.e. host)
72 * Consequently, on little endian target systems, this is a no-op and
73 * on big endian target systems, this performs a reordering.
75 * @param[in] inValue The 64-bit value to be byte order swapped.
77 * @return The input value, byte order swapped.
79 static inline uint64_t nlByteOrderSwap64LittleToHost(uint64_t inValue)
81 return nlByteOrderValueSwap64(inValue);
85 * This conditionally performs, as necessary for the target system, a
86 * byte order swap by value of the specified 16-bit value, presumed to
87 * be in target system (i.e. host) byte ordering to little endian byte
90 * Consequently, on little endian target systems, this is a no-op and
91 * on big endian target systems, this performs a reordering.
93 * @param[in] inValue The 16-bit value to be byte order swapped.
95 * @return The input value, byte order swapped.
97 static inline uint16_t nlByteOrderSwap16HostToLittle(uint16_t inValue)
99 return nlByteOrderValueSwap16(inValue);
103 * This conditionally performs, as necessary for the target system, a
104 * byte order swap by value of the specified 32-bit value, presumed to
105 * be in target system (i.e. host) byte ordering to little endian byte
108 * Consequently, on little endian target systems, this is a no-op and
109 * on big endian target systems, this performs a reordering.
111 * @param[in] inValue The 32-bit value to be byte order swapped.
113 * @return The input value, byte order swapped.
115 static inline uint32_t nlByteOrderSwap32HostToLittle(uint32_t inValue)
117 return nlByteOrderValueSwap32(inValue);
121 * This conditionally performs, as necessary for the target system, a
122 * byte order swap by value of the specified 64-bit value, presumed to
123 * be in target system (i.e. host) byte ordering to little endian byte
126 * Consequently, on little endian target systems, this is a no-op and
127 * on big endian target systems, this performs a reordering.
129 * @param[in] inValue The 64-bit value to be byte order swapped.
131 * @return The input value, byte order swapped.
133 static inline uint64_t nlByteOrderSwap64HostToLittle(uint64_t inValue)
135 return nlByteOrderValueSwap64(inValue);
139 * This conditionally performs, as necessary for the target system, a
140 * byte order swap by value of the specified 16-bit value, presumed to
141 * be in big endian byte ordering to the target system (i.e. host)
144 * Consequently, on little endian target systems, this performs a
145 * reordering and on big endian target systems, this is a no-op.
147 * @param[in] inValue The 16-bit value to be byte order swapped.
149 * @return The input value, byte order swapped.
151 static inline uint16_t nlByteOrderSwap16BigToHost(uint16_t inValue)
157 * This conditionally performs, as necessary for the target system, a
158 * byte order swap by value of the specified 32-bit value, presumed to
159 * be in big endian byte ordering to the target system (i.e. host)
162 * Consequently, on little endian target systems, this performs a
163 * reordering and on big endian target systems, this is a no-op.
165 * @param[in] inValue The 32-bit value to be byte order swapped.
167 * @return The input value, byte order swapped.
169 static inline uint32_t nlByteOrderSwap32BigToHost(uint32_t inValue)
175 * This conditionally performs, as necessary for the target system, a
176 * byte order swap by value of the specified 64-bit value, presumed to
177 * be in big endian byte ordering to the target system (i.e. host)
180 * Consequently, on little endian target systems, this performs a
181 * reordering and on big endian target systems, this is a no-op.
183 * @param[in] inValue The 64-bit value to be byte order swapped.
185 * @return The input value, byte order swapped.
187 static inline uint64_t nlByteOrderSwap64BigToHost(uint64_t inValue)
193 * This conditionally performs, as necessary for the target system, a
194 * byte order swap by value of the specified 16-bit value, presumed to
195 * be in target system (i.e. host) byte ordering to big endian byte
198 * Consequently, on little endian target systems, this performs a
199 * reordering and on big endian target systems, this is a no-op.
201 * @param[in] inValue The 16-bit value to be byte order swapped.
203 * @return The input value, byte order swapped.
205 static inline uint16_t nlByteOrderSwap16HostToBig(uint16_t inValue)
211 * This conditionally performs, as necessary for the target system, a
212 * byte order swap by value of the specified 32-bit value, presumed to
213 * be in target system (i.e. host) byte ordering to big endian byte
216 * Consequently, on little endian target systems, this performs a
217 * reordering and on big endian target systems, this is a no-op.
219 * @param[in] inValue The 32-bit value to be byte order swapped.
221 * @return The input value, byte order swapped.
223 static inline uint32_t nlByteOrderSwap32HostToBig(uint32_t inValue)
229 * This conditionally performs, as necessary for the target system, a
230 * byte order swap by value of the specified 64-bit value, presumed to
231 * be in target system (i.e. host) byte ordering to big endian byte
234 * Consequently, on little endian target systems, this performs a
235 * reordering and on big endian target systems, this is a no-op.
237 * @param[in] inValue The 64-bit value to be byte order swapped.
239 * @return The input value, byte order swapped.
241 static inline uint64_t nlByteOrderSwap64HostToBig(uint64_t inValue)
246 #endif /* NLBYTEORDER_BIG_H */