Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / nlio / repo / include / nlbyteorder.hpp
1 /**
2  *    Copyright 2012-2016 Nest Labs Inc. All Rights Reserved.
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  *    @file
19  *      This file defines C++ functions for performing byte-swapping
20  *      by value and in place by pointer for 16-, 32-, and 64-bit
21  *      types.
22  *
23  */
24
25 #ifndef NLBYTEORDER_HPP
26 #define NLBYTEORDER_HPP
27
28 #include <nlbyteorder.h>
29
30 namespace nl
31 {
32
33     namespace ByteOrder
34     {
35         enum {
36             Unknown      = nlByteOrderUnknown,
37             LittleEndian = nlByteOrderLittleEndian,
38             BigEndian    = nlByteOrderBigEndian    
39         };
40
41         /**
42          * This represents a type for a byte ordering.
43          */
44         typedef nlByteOrder ByteOrder;
45
46         /**
47          * This returns the byte order of the current system.
48          *
49          * @return The byte order of the current system.
50          */
51         inline ByteOrder GetCurrent(void)
52         {
53             return nlByteOrderGetCurrent();
54         }
55
56         /**
57          * This unconditionally performs a byte order swap by value of the
58          * specified 16-bit value.
59          *
60          * @param[in]  inValue  The 16-bit value to be byte order swapped.
61          *
62          * @return The input value, byte order swapped.
63          */
64         inline uint16_t Swap16(uint16_t inValue)
65         {
66             return nlByteOrderValueSwap16(inValue);
67         }
68
69         /**
70          * This unconditionally performs a byte order swap by value of the
71          * specified 32-bit value.
72          *
73          * @param[in]  inValue  The 32-bit value to be byte order swapped.
74          *
75          * @return The input value, byte order swapped.
76          */
77         inline uint32_t Swap32(uint32_t inValue)
78         {
79             return nlByteOrderValueSwap32(inValue);
80         }
81
82         /**
83          * This unconditionally performs a byte order swap by value of the
84          * specified 64-bit value.
85          *
86          * @param[in]  inValue  The 64-bit value to be byte order swapped.
87          *
88          * @return The input value, byte order swapped.
89          */
90         inline uint64_t Swap64(uint64_t inValue)
91         {
92             return nlByteOrderValueSwap64(inValue);
93         }
94
95         /**
96          * This unconditionally performs a byte order swap by pointer in place
97          * of the specified 16-bit value.
98          *
99          * @warning  The input value is assumed to be on a natural alignment
100          * boundary for the target system. It is the responsibility of the
101          * caller to perform any necessary alignment to avoid system faults
102          * for systems that do not support unaligned accesses.
103          *
104          * @param[inout]  inValue  A pointer to the 16-bit value to be byte
105          *                         order swapped.
106          */
107         inline void Swap16(uint16_t *inValue)
108         {
109             nlByteOrderPointerSwap16(inValue);
110         }
111
112         /**
113          * This unconditionally performs a byte order swap by pointer in place
114          * of the specified 32-bit value.
115          *
116          * @warning  The input value is assumed to be on a natural alignment
117          * boundary for the target system. It is the responsibility of the
118          * caller to perform any necessary alignment to avoid system faults
119          * for systems that do not support unaligned accesses.
120          *
121          * @param[inout]  inValue  A pointer to the 32-bit value to be byte
122          *                         order swapped.
123          */
124         inline void Swap32(uint32_t *inValue)
125         {
126             nlByteOrderPointerSwap32(inValue);
127         }
128
129         /**
130          * This unconditionally performs a byte order swap by pointer in place
131          * of the specified 64-bit value.
132          *
133          * @warning  The input value is assumed to be on a natural alignment
134          * boundary for the target system. It is the responsibility of the
135          * caller to perform any necessary alignment to avoid system faults
136          * for systems that do not support unaligned accesses.
137          *
138          * @param[inout]  inValue  A pointer to the 64-bit value to be byte
139          *                         order swapped.
140          */
141         inline void Swap64(uint64_t *inValue)
142         {
143             nlByteOrderPointerSwap64(inValue);
144         }
145
146         /**
147          * This conditionally performs, as necessary for the target system, a
148          * byte order swap by value of the specified 16-bit value, presumed to
149          * be in little endian byte ordering to the target system (i.e. host)
150          * byte ordering.
151          *
152          * Consequently, on little endian target systems, this is a no-op and
153          * on big endian target systems, this performs a reordering.
154          *
155          * @param[in]  inValue  The 16-bit value to be byte order swapped.
156          *
157          * @return The input value, byte order swapped.
158          */
159         inline uint16_t Swap16LittleToHost(uint16_t inValue)
160         {
161             return nlByteOrderSwap16LittleToHost(inValue);
162         }
163
164         /**
165          * This conditionally performs, as necessary for the target system, a
166          * byte order swap by value of the specified 32-bit value, presumed to
167          * be in little endian byte ordering to the target system (i.e. host)
168          * byte ordering.
169          *
170          * Consequently, on little endian target systems, this is a no-op and
171          * on big endian target systems, this performs a reordering.
172          *
173          * @param[in]  inValue  The 32-bit value to be byte order swapped.
174          *
175          * @return The input value, byte order swapped.
176          */
177         inline uint32_t Swap32LittleToHost(uint32_t inValue)
178         {
179             return nlByteOrderSwap32LittleToHost(inValue);
180         }
181
182         /**
183          * This conditionally performs, as necessary for the target system, a
184          * byte order swap by value of the specified 64-bit value, presumed to
185          * be in little endian byte ordering to the target system (i.e. host)
186          * byte ordering.
187          *
188          * Consequently, on little endian target systems, this is a no-op and
189          * on big endian target systems, this performs a reordering.
190          *
191          * @param[in]  inValue  The 64-bit value to be byte order swapped.
192          *
193          * @return The input value, byte order swapped.
194          */
195         inline uint64_t Swap64LittleToHost(uint64_t inValue)
196         {
197             return nlByteOrderSwap64LittleToHost(inValue);
198         }
199
200         /**
201          * This conditionally performs, as necessary for the target system, a
202          * byte order swap by value of the specified 16-bit value, presumed to
203          * be in target system (i.e. host) byte ordering to little endian byte
204          * ordering.
205          *
206          * Consequently, on little endian target systems, this is a no-op and
207          * on big endian target systems, this performs a reordering.
208          *
209          * @param[in]  inValue  The 16-bit value to be byte order swapped.
210          *
211          * @return The input value, byte order swapped.
212          */
213         inline uint16_t Swap16HostToLittle(uint16_t inValue)
214         {
215             return nlByteOrderSwap16HostToLittle(inValue);
216         }
217
218         /**
219          * This conditionally performs, as necessary for the target system, a
220          * byte order swap by value of the specified 32-bit value, presumed to
221          * be in target system (i.e. host) byte ordering to little endian byte
222          * ordering.
223          *
224          * Consequently, on little endian target systems, this is a no-op and
225          * on big endian target systems, this performs a reordering.
226          *
227          * @param[in]  inValue  The 32-bit value to be byte order swapped.
228          *
229          * @return The input value, byte order swapped.
230          */
231         inline uint32_t Swap32HostToLittle(uint32_t inValue)
232         {
233             return nlByteOrderSwap32HostToLittle(inValue);
234         }
235
236         /**
237          * This conditionally performs, as necessary for the target system, a
238          * byte order swap by value of the specified 64-bit value, presumed to
239          * be in target system (i.e. host) byte ordering to little endian byte
240          * ordering.
241          *
242          * Consequently, on little endian target systems, this is a no-op and
243          * on big endian target systems, this performs a reordering.
244          *
245          * @param[in]  inValue  The 64-bit value to be byte order swapped.
246          *
247          * @return The input value, byte order swapped.
248          */
249         inline uint64_t Swap64HostToLittle(uint64_t inValue)
250         {
251             return nlByteOrderSwap64HostToLittle(inValue);
252         }
253
254         /**
255          * This conditionally performs, as necessary for the target system, a
256          * byte order swap by value of the specified 16-bit value, presumed to
257          * be in big endian byte ordering to the target system (i.e. host)
258          * byte ordering.
259          *
260          * Consequently, on little endian target systems, this performs a
261          * reordering and on big endian target systems, this is a no-op.
262          *
263          * @param[in]  inValue  The 16-bit value to be byte order swapped.
264          *
265          * @return The input value, byte order swapped.
266          */
267         inline uint16_t Swap16BigToHost(uint16_t inValue)
268         {
269             return nlByteOrderSwap16BigToHost(inValue);
270         }
271
272         /**
273          * This conditionally performs, as necessary for the target system, a
274          * byte order swap by value of the specified 32-bit value, presumed to
275          * be in big endian byte ordering to the target system (i.e. host)
276          * byte ordering.
277          *
278          * Consequently, on little endian target systems, this performs a
279          * reordering and on big endian target systems, this is a no-op.
280          *
281          * @param[in]  inValue  The 32-bit value to be byte order swapped.
282          *
283          * @return The input value, byte order swapped.
284          */
285         inline uint32_t Swap32BigToHost(uint32_t inValue)
286         {
287             return nlByteOrderSwap32BigToHost(inValue);
288         }
289
290         /**
291          * This conditionally performs, as necessary for the target system, a
292          * byte order swap by value of the specified 64-bit value, presumed to
293          * be in big endian byte ordering to the target system (i.e. host)
294          * byte ordering.
295          *
296          * Consequently, on little endian target systems, this performs a
297          * reordering and on big endian target systems, this is a no-op.
298          *
299          * @param[in]  inValue  The 64-bit value to be byte order swapped.
300          *
301          * @return The input value, byte order swapped.
302          */
303         inline uint64_t Swap64BigToHost(uint64_t inValue)
304         {
305             return nlByteOrderSwap64BigToHost(inValue);
306         }
307
308         /**
309          * This conditionally performs, as necessary for the target system, a
310          * byte order swap by value of the specified 16-bit value, presumed to
311          * be in target system (i.e. host) byte ordering to big endian byte
312          * ordering.
313          *
314          * Consequently, on little endian target systems, this performs a
315          * reordering and on big endian target systems, this is a no-op.
316          *
317          * @param[in]  inValue  The 16-bit value to be byte order swapped.
318          *
319          * @return The input value, byte order swapped.
320          */
321         inline uint16_t Swap16HostToBig(uint16_t inValue)
322         {
323             return nlByteOrderSwap16HostToBig(inValue);
324         }
325
326         /**
327          * This conditionally performs, as necessary for the target system, a
328          * byte order swap by value of the specified 32-bit value, presumed to
329          * be in target system (i.e. host) byte ordering to big endian byte
330          * ordering.
331          *
332          * Consequently, on little endian target systems, this performs a
333          * reordering and on big endian target systems, this is a no-op.
334          *
335          * @param[in]  inValue  The 32-bit value to be byte order swapped.
336          *
337          * @return The input value, byte order swapped.
338          */
339         inline uint32_t Swap32HostToBig(uint32_t inValue)
340         {
341             return nlByteOrderSwap32HostToBig(inValue);
342         }
343
344         /**
345          * This conditionally performs, as necessary for the target system, a
346          * byte order swap by value of the specified 64-bit value, presumed to
347          * be in target system (i.e. host) byte ordering to big endian byte
348          * ordering.
349          *
350          * Consequently, on little endian target systems, this performs a
351          * reordering and on big endian target systems, this is a no-op.
352          *
353          * @param[in]  inValue  The 64-bit value to be byte order swapped.
354          *
355          * @return The input value, byte order swapped.
356          */
357         inline uint64_t Swap64HostToBig(uint64_t inValue)
358         {
359             return nlByteOrderSwap64HostToBig(inValue);
360         }
361
362     } // namespace ByteOrder
363
364 } // namespace nl
365
366 #endif // NLBYTEORDER_HPP
367
368
369
370
371
372
373
374
375
376
377
378