Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / nlio / repo / include / nlbyteorder-big.h
1 /**
2  *    Copyright (c) 2020 nlio Authors. All Rights Reserved.
3  *    Copyright 2012-2016 Nest Labs Inc. All Rights Reserved.
4  *
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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 /**
19  *    @file
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.
25  */
26
27 #ifndef NLBYTEORDER_BIG_H
28 #define NLBYTEORDER_BIG_H
29
30 /**
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)
34  * byte ordering.
35  *
36  * Consequently, on little endian target systems, this is a no-op and
37  * on big endian target systems, this performs a reordering.
38  *
39  * @param[in]  inValue  The 16-bit value to be byte order swapped.
40  *
41  * @return The input value, byte order swapped.
42  */
43 static inline uint16_t nlByteOrderSwap16LittleToHost(uint16_t inValue)
44 {
45     return nlByteOrderValueSwap16(inValue);
46 }
47
48 /**
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)
52  * byte ordering.
53  *
54  * Consequently, on little endian target systems, this is a no-op and
55  * on big endian target systems, this performs a reordering.
56  *
57  * @param[in]  inValue  The 32-bit value to be byte order swapped.
58  *
59  * @return The input value, byte order swapped.
60  */
61 static inline uint32_t nlByteOrderSwap32LittleToHost(uint32_t inValue)
62 {
63     return nlByteOrderValueSwap32(inValue);
64 }
65
66 /**
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)
70  * byte ordering.
71  *
72  * Consequently, on little endian target systems, this is a no-op and
73  * on big endian target systems, this performs a reordering.
74  *
75  * @param[in]  inValue  The 64-bit value to be byte order swapped.
76  *
77  * @return The input value, byte order swapped.
78  */
79 static inline uint64_t nlByteOrderSwap64LittleToHost(uint64_t inValue)
80 {
81     return nlByteOrderValueSwap64(inValue);
82 }
83
84 /**
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
88  * ordering.
89  *
90  * Consequently, on little endian target systems, this is a no-op and
91  * on big endian target systems, this performs a reordering.
92  *
93  * @param[in]  inValue  The 16-bit value to be byte order swapped.
94  *
95  * @return The input value, byte order swapped.
96  */
97 static inline uint16_t nlByteOrderSwap16HostToLittle(uint16_t inValue)
98 {
99     return nlByteOrderValueSwap16(inValue);
100 }
101
102 /**
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
106  * ordering.
107  *
108  * Consequently, on little endian target systems, this is a no-op and
109  * on big endian target systems, this performs a reordering.
110  *
111  * @param[in]  inValue  The 32-bit value to be byte order swapped.
112  *
113  * @return The input value, byte order swapped.
114  */
115 static inline uint32_t nlByteOrderSwap32HostToLittle(uint32_t inValue)
116 {
117     return nlByteOrderValueSwap32(inValue);
118 }
119
120 /**
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
124  * ordering.
125  *
126  * Consequently, on little endian target systems, this is a no-op and
127  * on big endian target systems, this performs a reordering.
128  *
129  * @param[in]  inValue  The 64-bit value to be byte order swapped.
130  *
131  * @return The input value, byte order swapped.
132  */
133 static inline uint64_t nlByteOrderSwap64HostToLittle(uint64_t inValue)
134 {
135     return nlByteOrderValueSwap64(inValue);
136 }
137
138 /**
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)
142  * byte ordering.
143  *
144  * Consequently, on little endian target systems, this performs a
145  * reordering and on big endian target systems, this is a no-op.
146  *
147  * @param[in]  inValue  The 16-bit value to be byte order swapped.
148  *
149  * @return The input value, byte order swapped.
150  */
151 static inline uint16_t nlByteOrderSwap16BigToHost(uint16_t inValue)
152 {
153     return inValue;
154 }
155
156 /**
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)
160  * byte ordering.
161  *
162  * Consequently, on little endian target systems, this performs a
163  * reordering and on big endian target systems, this is a no-op.
164  *
165  * @param[in]  inValue  The 32-bit value to be byte order swapped.
166  *
167  * @return The input value, byte order swapped.
168  */
169 static inline uint32_t nlByteOrderSwap32BigToHost(uint32_t inValue)
170 {
171     return inValue;
172 }
173
174 /**
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)
178  * byte ordering.
179  *
180  * Consequently, on little endian target systems, this performs a
181  * reordering and on big endian target systems, this is a no-op.
182  *
183  * @param[in]  inValue  The 64-bit value to be byte order swapped.
184  *
185  * @return The input value, byte order swapped.
186  */
187 static inline uint64_t nlByteOrderSwap64BigToHost(uint64_t inValue)
188 {
189     return inValue;
190 }
191
192 /**
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
196  * ordering.
197  *
198  * Consequently, on little endian target systems, this performs a
199  * reordering and on big endian target systems, this is a no-op.
200  *
201  * @param[in]  inValue  The 16-bit value to be byte order swapped.
202  *
203  * @return The input value, byte order swapped.
204  */
205 static inline uint16_t nlByteOrderSwap16HostToBig(uint16_t inValue)
206 {
207     return inValue;
208 }
209
210 /**
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
214  * ordering.
215  *
216  * Consequently, on little endian target systems, this performs a
217  * reordering and on big endian target systems, this is a no-op.
218  *
219  * @param[in]  inValue  The 32-bit value to be byte order swapped.
220  *
221  * @return The input value, byte order swapped.
222  */
223 static inline uint32_t nlByteOrderSwap32HostToBig(uint32_t inValue)
224 {
225     return inValue;
226 }
227
228 /**
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
232  * ordering.
233  *
234  * Consequently, on little endian target systems, this performs a
235  * reordering and on big endian target systems, this is a no-op.
236  *
237  * @param[in]  inValue  The 64-bit value to be byte order swapped.
238  *
239  * @return The input value, byte order swapped.
240  */
241 static inline uint64_t nlByteOrderSwap64HostToBig(uint64_t inValue)
242 {
243     return inValue;
244 }
245
246 #endif /* NLBYTEORDER_BIG_H */
247