2 * Copyright 2012-2016 Nest Labs Inc. All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 * This file defines defines functions for performing by value
20 * byte reordering for 16-, 32-, and 64-bit quantities both
21 * to-and-from the target system (i.e. host) byte ordering
22 * to-and-from both little and big endian byte ordering,
23 * specifically for little endian target systems.
26 #ifndef NLBYTEORDER_LITTLE_H
27 #define NLBYTEORDER_LITTLE_H
30 * This conditionally performs, as necessary for the target system, a
31 * byte order swap by value of the specified 16-bit value, presumed to
32 * be in little endian byte ordering to the target system (i.e. host)
35 * Consequently, on little endian target systems, this is a no-op and
36 * on big endian target systems, this performs a reordering.
38 * @param[in] inValue The 16-bit value to be byte order swapped.
40 * @return The input value, byte order swapped.
42 static inline uint16_t nlByteOrderSwap16LittleToHost(uint16_t inValue)
48 * This conditionally performs, as necessary for the target system, a
49 * byte order swap by value of the specified 32-bit value, presumed to
50 * be in little endian byte ordering to the target system (i.e. host)
53 * Consequently, on little endian target systems, this is a no-op and
54 * on big endian target systems, this performs a reordering.
56 * @param[in] inValue The 32-bit value to be byte order swapped.
58 * @return The input value, byte order swapped.
60 static inline uint32_t nlByteOrderSwap32LittleToHost(uint32_t inValue)
66 * This conditionally performs, as necessary for the target system, a
67 * byte order swap by value of the specified 64-bit value, presumed to
68 * be in little endian byte ordering to the target system (i.e. host)
71 * Consequently, on little endian target systems, this is a no-op and
72 * on big endian target systems, this performs a reordering.
74 * @param[in] inValue The 64-bit value to be byte order swapped.
76 * @return The input value, byte order swapped.
78 static inline uint64_t nlByteOrderSwap64LittleToHost(uint64_t inValue)
84 * This conditionally performs, as necessary for the target system, a
85 * byte order swap by value of the specified 16-bit value, presumed to
86 * be in target system (i.e. host) byte ordering to little endian byte
89 * Consequently, on little endian target systems, this is a no-op and
90 * on big endian target systems, this performs a reordering.
92 * @param[in] inValue The 16-bit value to be byte order swapped.
94 * @return The input value, byte order swapped.
96 static inline uint16_t nlByteOrderSwap16HostToLittle(uint16_t inValue)
102 * This conditionally performs, as necessary for the target system, a
103 * byte order swap by value of the specified 32-bit value, presumed to
104 * be in target system (i.e. host) byte ordering to little endian byte
107 * Consequently, on little endian target systems, this is a no-op and
108 * on big endian target systems, this performs a reordering.
110 * @param[in] inValue The 32-bit value to be byte order swapped.
112 * @return The input value, byte order swapped.
114 static inline uint32_t nlByteOrderSwap32HostToLittle(uint32_t inValue)
120 * This conditionally performs, as necessary for the target system, a
121 * byte order swap by value of the specified 64-bit value, presumed to
122 * be in target system (i.e. host) byte ordering to little endian byte
125 * Consequently, on little endian target systems, this is a no-op and
126 * on big endian target systems, this performs a reordering.
128 * @param[in] inValue The 64-bit value to be byte order swapped.
130 * @return The input value, byte order swapped.
132 static inline uint64_t nlByteOrderSwap64HostToLittle(uint64_t inValue)
138 * This conditionally performs, as necessary for the target system, a
139 * byte order swap by value of the specified 16-bit value, presumed to
140 * be in big endian byte ordering to the target system (i.e. host)
143 * Consequently, on little endian target systems, this performs a
144 * reordering and on big endian target systems, this is a no-op.
146 * @param[in] inValue The 16-bit value to be byte order swapped.
148 * @return The input value, byte order swapped.
150 static inline uint16_t nlByteOrderSwap16BigToHost(uint16_t inValue)
152 return nlByteOrderValueSwap16(inValue);
156 * This conditionally performs, as necessary for the target system, a
157 * byte order swap by value of the specified 32-bit value, presumed to
158 * be in big endian byte ordering to the target system (i.e. host)
161 * Consequently, on little endian target systems, this performs a
162 * reordering and on big endian target systems, this is a no-op.
164 * @param[in] inValue The 32-bit value to be byte order swapped.
166 * @return The input value, byte order swapped.
168 static inline uint32_t nlByteOrderSwap32BigToHost(uint32_t inValue)
170 return nlByteOrderValueSwap32(inValue);
174 * This conditionally performs, as necessary for the target system, a
175 * byte order swap by value of the specified 64-bit value, presumed to
176 * be in big endian byte ordering to the target system (i.e. host)
179 * Consequently, on little endian target systems, this performs a
180 * reordering and on big endian target systems, this is a no-op.
182 * @param[in] inValue The 64-bit value to be byte order swapped.
184 * @return The input value, byte order swapped.
186 static inline uint64_t nlByteOrderSwap64BigToHost(uint64_t inValue)
188 return nlByteOrderValueSwap64(inValue);
192 * This conditionally performs, as necessary for the target system, a
193 * byte order swap by value of the specified 16-bit value, presumed to
194 * be in target system (i.e. host) byte ordering to big endian byte
197 * Consequently, on little endian target systems, this performs a
198 * reordering and on big endian target systems, this is a no-op.
200 * @param[in] inValue The 16-bit value to be byte order swapped.
202 * @return The input value, byte order swapped.
204 static inline uint16_t nlByteOrderSwap16HostToBig(uint16_t inValue)
206 return nlByteOrderValueSwap16(inValue);
210 * This conditionally performs, as necessary for the target system, a
211 * byte order swap by value of the specified 32-bit value, presumed to
212 * be in target system (i.e. host) byte ordering to big endian byte
215 * Consequently, on little endian target systems, this performs a
216 * reordering and on big endian target systems, this is a no-op.
218 * @param[in] inValue The 32-bit value to be byte order swapped.
220 * @return The input value, byte order swapped.
222 static inline uint32_t nlByteOrderSwap32HostToBig(uint32_t inValue)
224 return nlByteOrderValueSwap32(inValue);
228 * This conditionally performs, as necessary for the target system, a
229 * byte order swap by value of the specified 64-bit value, presumed to
230 * be in target system (i.e. host) byte ordering to big endian byte
233 * Consequently, on little endian target systems, this performs a
234 * reordering and on big endian target systems, this is a no-op.
236 * @param[in] inValue The 64-bit value to be byte order swapped.
238 * @return The input value, byte order swapped.
240 static inline uint64_t nlByteOrderSwap64HostToBig(uint64_t inValue)
242 return nlByteOrderValueSwap64(inValue);
245 #endif /* NLBYTEORDER_LITTLE_H */