Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / nlio / repo / include / nlio-byteorder-big.hpp
1 /**
2  *    Copyright 2013-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 safely performing simple,
20  *      memory-mapped accesses, potentially to unaligned, aligned, and
21  *      unaligned memory locations with byte reordering, specifically
22  *      for big endian target systems.
23  */
24
25 #ifndef NLIO_BYTEORDER_BIG_HPP
26 #define NLIO_BYTEORDER_BIG_HPP
27
28 #include <nlio-base.hpp>
29 #include <nlbyteorder.hpp>
30
31 namespace nl
32 {
33
34 namespace IO
35 {
36
37 namespace BigEndian
38 {
39
40 /**
41  * Perform a, potentially unaligned, memory read of the big endian
42  * byte ordered 8-bit value from the specified pointer address,
43  * perform byte reordering, as necessary, for the target system to
44  * put the value in target system byte ordering.
45  *
46  * @param[in]  p      A pointer address, potentially unaligned, to read
47  *                    the 8-bit big endian byte ordered value from.
48  *
49  * @return The 8-bit value at the specified pointer address.
50  */
51 static inline uint8_t  Get8(const void *p)
52 {
53     return IO::Get8(p);
54 }
55
56 /**
57  * Perform a, potentially unaligned, memory read of the big endian
58  * byte ordered 16-bit value from the specified pointer address,
59  * perform byte reordering, as necessary, for the target system to
60  * put the value in target system byte ordering.
61  *
62  * @param[in]  p      A pointer address, potentially unaligned, to read
63  *                    the 16-bit big endian byte ordered value from.
64  *
65  * @return The 16-bit value at the specified pointer address.
66  */
67 static inline uint16_t Get16(const void *p)
68 {
69     return ByteOrder::Swap16BigToHost(IO::Get16(p));
70 }
71
72 /**
73  * Perform a, potentially unaligned, memory read of the big endian
74  * byte ordered 32-bit value from the specified pointer address,
75  * perform byte reordering, as necessary, for the target system to
76  * put the value in target system byte ordering.
77  *
78  * @param[in]  p      A pointer address, potentially unaligned, to read
79  *                    the 32-bit big endian byte ordered value from.
80  *
81  * @return The 32-bit value at the specified pointer address.
82  */
83 static inline uint32_t Get32(const void *p)
84 {
85     return ByteOrder::Swap32BigToHost(IO::Get32(p));
86 }
87
88 /**
89  * Perform a, potentially unaligned, memory read of the big endian
90  * byte ordered 64-bit value from the specified pointer address,
91  * perform byte reordering, as necessary, for the target system to
92  * put the value in target system byte ordering.
93  *
94  * @param[in]  p      A pointer address, potentially unaligned, to read
95  *                    the 64-bit big endian byte ordered value from.
96  *
97  * @return The 64-bit value at the specified pointer address.
98  */
99 static inline uint64_t Get64(const void *p)
100 {
101     return ByteOrder::Swap64BigToHost(IO::Get64(p));
102 }
103
104 /**
105  * Perform a, potentially unaligned, memory write of the target system
106  * byte ordered 8-bit value to the specified pointer address,
107  * perform byte reordering, as necessary, for the target system to
108  * put the value in big endian byte ordering.
109  *
110  * @param[in]  p      A pointer address, potentially unaligned, to write
111  *                    the target system byte ordered 8-bit value to in big
112  *                    endian byte ordering.
113  *
114  * @param[in]  v      The 8-bit value to write.
115  *
116  */
117 static inline void     Put8(void *p, uint8_t v)
118 {
119     IO::Put8(p, v);
120 }
121
122 /**
123  * Perform a, potentially unaligned, memory write of the target system
124  * byte ordered 16-bit value to the specified pointer address,
125  * perform byte reordering, as necessary, for the target system to
126  * put the value in big endian byte ordering.
127  *
128  * @param[in]  p      A pointer address, potentially unaligned, to write
129  *                    the target system byte ordered 16-bit value to in big
130  *                    endian byte ordering.
131  *
132  * @param[in]  v      The 16-bit value to write.
133  *
134  */
135 static inline void     Put16(void *p, uint16_t v)
136 {
137     IO::Put16(p, ByteOrder::Swap16HostToBig(v));
138 }
139
140 /**
141  * Perform a, potentially unaligned, memory write of the target system
142  * byte ordered 32-bit value to the specified pointer address,
143  * perform byte reordering, as necessary, for the target system to
144  * put the value in big endian byte ordering.
145  *
146  * @param[in]  p      A pointer address, potentially unaligned, to write
147  *                    the target system byte ordered 32-bit value to in big
148  *                    endian byte ordering.
149  *
150  * @param[in]  v      The 32-bit value to write.
151  *
152  */
153 static inline void     Put32(void *p, uint32_t v)
154 {
155     IO::Put32(p, ByteOrder::Swap32HostToBig(v));
156 }
157
158 /**
159  * Perform a, potentially unaligned, memory write of the target system
160  * byte ordered 64-bit value to the specified pointer address,
161  * perform byte reordering, as necessary, for the target system to
162  * put the value in big endian byte ordering.
163  *
164  * @param[in]  p      A pointer address, potentially unaligned, to write
165  *                    the target system byte ordered 64-bit value to in big
166  *                    endian byte ordering.
167  *
168  * @param[in]  v      The 64-bit value to write.
169  *
170  */
171 static inline void     Put64(void *p, uint64_t v)
172 {
173     IO::Put64(p, ByteOrder::Swap64HostToBig(v));
174 }
175
176 /**
177  * Perform a, potentially unaligned, memory read of the big endian
178  * byte ordered 8-bit value from the specified pointer address,
179  * perform byte reordering, as necessary, for the target system to put
180  * the value in target system byte ordering, and increment the pointer
181  * by 8-bits (1 byte).
182  *
183  * @param[inout]  p   A reference to a pointer address, potentially
184  *                    unaligned, to read the 8-bit big endian byte
185  *                    ordered value from and to then increment by 8-
186  *                    bits (1 byte).
187  *
188  * @return The 8-bit value at the specified pointer address.
189  */
190 static inline uint8_t  Read8(const void *&p)
191 {
192     return IO::Read8(p);
193 }
194
195 /**
196  * Perform a, potentially unaligned, memory read of the big endian
197  * byte ordered 16-bit value from the specified pointer address,
198  * perform byte reordering, as necessary, for the target system to put
199  * the value in target system byte ordering, and increment the pointer
200  * by 16-bits (2 bytes).
201  *
202  * @param[inout]  p   A reference to a pointer address, potentially
203  *                    unaligned, to read the 16-bit big endian byte
204  *                    ordered value from and to then increment by 16-
205  *                    bits (2 bytes).
206  *
207  * @return The 16-bit value at the specified pointer address.
208  */
209 static inline uint16_t Read16(const void *&p)
210 {
211     return ByteOrder::Swap16BigToHost(IO::Read16(p));
212 }
213
214 /**
215  * Perform a, potentially unaligned, memory read of the big endian
216  * byte ordered 32-bit value from the specified pointer address,
217  * perform byte reordering, as necessary, for the target system to put
218  * the value in target system byte ordering, and increment the pointer
219  * by 32-bits (4 bytes).
220  *
221  * @param[inout]  p   A reference to a pointer address, potentially
222  *                    unaligned, to read the 32-bit big endian byte
223  *                    ordered value from and to then increment by 32-
224  *                    bits (4 bytes).
225  *
226  * @return The 32-bit value at the specified pointer address.
227  */
228 static inline uint32_t Read32(const void *&p)
229 {
230     return ByteOrder::Swap32BigToHost(IO::Read32(p));
231 }
232
233 /**
234  * Perform a, potentially unaligned, memory read of the big endian
235  * byte ordered 64-bit value from the specified pointer address,
236  * perform byte reordering, as necessary, for the target system to put
237  * the value in target system byte ordering, and increment the pointer
238  * by 64-bits (8 bytes).
239  *
240  * @param[inout]  p   A reference to a pointer address, potentially
241  *                    unaligned, to read the 64-bit big endian byte
242  *                    ordered value from and to then increment by 64-
243  *                    bits (8 bytes).
244  *
245  * @return The 64-bit value at the specified pointer address.
246  */
247 static inline uint64_t Read64(const void *&p)
248 {
249     return ByteOrder::Swap64BigToHost(IO::Read64(p));
250 }
251
252 /**
253  * Perform a, potentially unaligned, memory write of the target system
254  * byte ordered 8-bit value to the specified pointer address,
255  * perform byte reordering, as necessary, for the target system to
256  * put the value in big endian byte ordering.
257  *
258  * @param[in]  p      A reference to a pointer address, potentially
259  *                    unaligned, to write the target system byte
260  *                    ordered 8-bit value to in big endian byte
261  *                    ordering and to then increment by 8-bits (1
262  *                    byte).
263  *
264  * @param[in]  v      The 8-bit value to write.
265  *
266  */
267 static inline void     Write8(void *&p, uint8_t v)
268 {
269     IO::Write8(p, v);
270 }
271
272 /**
273  * Perform a, potentially unaligned, memory write of the target system
274  * byte ordered 16-bit value to the specified pointer address,
275  * perform byte reordering, as necessary, for the target system to
276  * put the value in big endian byte ordering.
277  *
278  * @param[in]  p      A reference to a pointer address, potentially
279  *                    unaligned, to write the target system byte
280  *                    ordered 16-bit value to in big endian byte
281  *                    ordering and to then increment by 16-bits (2
282  *                    bytes).
283  *
284  * @param[in]  v      The 16-bit value to write.
285  *
286  */
287 static inline void     Write16(void *&p, uint16_t v)
288 {
289     IO::Write16(p, ByteOrder::Swap16HostToBig(v));
290 }
291
292 /**
293  * Perform a, potentially unaligned, memory write of the target system
294  * byte ordered 32-bit value to the specified pointer address,
295  * perform byte reordering, as necessary, for the target system to
296  * put the value in big endian byte ordering.
297  *
298  * @param[in]  p      A reference to a pointer address, potentially
299  *                    unaligned, to write the target system byte
300  *                    ordered 32-bit value to in big endian byte
301  *                    ordering and to then increment by 16-bits (4
302  *                    bytes).
303  *
304  * @param[in]  v      The 32-bit value to write.
305  *
306  */
307 static inline void     Write32(void *&p, uint32_t v)
308 {
309     IO::Write32(p, ByteOrder::Swap32HostToBig(v));
310 }
311
312 /**
313  * Perform a, potentially unaligned, memory write of the target system
314  * byte ordered 64-bit value to the specified pointer address,
315  * perform byte reordering, as necessary, for the target system to
316  * put the value in big endian byte ordering.
317  *
318  * @param[in]  p      A reference to a pointer address, potentially
319  *                    unaligned, to write the target system byte
320  *                    ordered 64-bit value to in big endian byte
321  *                    ordering and to then increment by 64-bits (8
322  *                    bytes).
323  *
324  * @param[in]  v      The 64-bit value to write.
325  *
326  */
327 static inline void     Write64(void *&p, uint64_t v)
328 {
329     IO::Write64(p, ByteOrder::Swap64HostToBig(v));
330 }
331
332 /**
333  * Perform an aligned memory read of the big endian
334  * byte ordered 8-bit value from the specified pointer address,
335  * perform byte reordering, as necessary, for the target system to
336  * put the value in target system byte ordering.
337  *
338  * @param[in]  p      An aligned pointer address to read
339  *                    the 8-bit big endian byte ordered value from.
340  *
341  * @return The 8-bit value at the specified pointer address.
342  */
343 static inline uint8_t  GetAligned8(const void *p)
344 {
345     return IO::GetAligned8(p);
346 }
347
348 /**
349  * Perform an aligned memory read of the big endian
350  * byte ordered 16-bit value from the specified pointer address,
351  * perform byte reordering, as necessary, for the target system to
352  * put the value in target system byte ordering.
353  *
354  * @param[in]  p      An aligned pointer address to read
355  *                    the 16-bit big endian byte ordered value from.
356  *
357  * @return The 16-bit value at the specified pointer address.
358  */
359 static inline uint16_t GetAligned16(const void *p)
360 {
361     return ByteOrder::Swap16BigToHost(IO::GetAligned16(p));
362 }
363
364 /**
365  * Perform an aligned memory read of the big endian
366  * byte ordered 32-bit value from the specified pointer address,
367  * perform byte reordering, as necessary, for the target system to
368  * put the value in target system byte ordering.
369  *
370  * @param[in]  p      An aligned pointer address to read
371  *                    the 32-bit big endian byte ordered value from.
372  *
373  * @return The 32-bit value at the specified pointer address.
374  */
375 static inline uint32_t GetAligned32(const void *p)
376 {
377     return ByteOrder::Swap32BigToHost(IO::GetAligned32(p));
378 }
379
380 /**
381  * Perform an aligned memory read of the big endian
382  * byte ordered 64-bit value from the specified pointer address,
383  * perform byte reordering, as necessary, for the target system to
384  * put the value in target system byte ordering.
385  *
386  * @param[in]  p      An aligned pointer address to read
387  *                    the 64-bit big endian byte ordered value from.
388  *
389  * @return The 64-bit value at the specified pointer address.
390  */
391 static inline uint64_t GetAligned64(const void *p)
392 {
393     return ByteOrder::Swap64BigToHost(IO::GetAligned64(p));
394 }
395
396 /**
397  * Perform an aligned memory write of the target system
398  * byte ordered 8-bit value to the specified pointer address,
399  * perform byte reordering, as necessary, for the target system to
400  * put the value in big endian byte ordering.
401  *
402  * @param[in]  p      An aligned pointer address to write
403  *                    the target system byte ordered 8-bit value to in big
404  *                    endian byte ordering.
405  *
406  * @param[in]  v      The 8-bit value to write.
407  *
408  */
409 static inline void     PutAligned8(void *p, uint8_t v)
410 {
411     IO::PutAligned8(p, v);
412 }
413
414 /**
415  * Perform an aligned memory write of the target system
416  * byte ordered 16-bit value to the specified pointer address,
417  * perform byte reordering, as necessary, for the target system to
418  * put the value in big endian byte ordering.
419  *
420  * @param[in]  p      An aligned pointer address to write
421  *                    the target system byte ordered 16-bit value to in big
422  *                    endian byte ordering.
423  *
424  * @param[in]  v      The 16-bit value to write.
425  *
426  */
427 static inline void     PutAligned16(void *p, uint16_t v)
428 {
429     IO::PutAligned16(p, ByteOrder::Swap16HostToBig(v));
430 }
431
432 /**
433  * Perform an aligned memory write of the target system
434  * byte ordered 32-bit value to the specified pointer address,
435  * perform byte reordering, as necessary, for the target system to
436  * put the value in big endian byte ordering.
437  *
438  * @param[in]  p      An aligned pointer address to write
439  *                    the target system byte ordered 32-bit value to in big
440  *                    endian byte ordering.
441  *
442  * @param[in]  v      The 32-bit value to write.
443  *
444  */
445 static inline void     PutAligned32(void *p, uint32_t v)
446 {
447     IO::PutAligned32(p, ByteOrder::Swap32HostToBig(v));
448 }
449
450 /**
451  * Perform an aligned memory write of the target system
452  * byte ordered 64-bit value to the specified pointer address,
453  * perform byte reordering, as necessary, for the target system to
454  * put the value in big endian byte ordering.
455  *
456  * @param[in]  p      An aligned pointer address to write
457  *                    the target system byte ordered 64-bit value to in big
458  *                    endian byte ordering.
459  *
460  * @param[in]  v      The 64-bit value to write.
461  *
462  */
463 static inline void     PutAligned64(void *p, uint64_t v)
464 {
465     IO::PutAligned64(p, ByteOrder::Swap64HostToBig(v));
466 }
467
468 /**
469  * Perform an aligned memory read of the big endian
470  * byte ordered 8-bit value from the specified pointer address,
471  * perform byte reordering, as necessary, for the target system to put
472  * the value in target system byte ordering, and increment the pointer
473  * by 8-bits (1 byte).
474  *
475  * @param[inout]  p   A reference to an aligned pointer address
476  *                    to read the 8-bit big endian byte
477  *                    ordered value from and to then increment by 8-
478  *                    bits (1 byte).
479  *
480  * @return The 8-bit value at the specified pointer address.
481  */
482 static inline uint8_t  ReadAligned8(const void *&p)
483 {
484     return IO::ReadAligned8(p);
485 }
486
487 /**
488  * Perform an aligned memory read of the big endian
489  * byte ordered 16-bit value from the specified pointer address,
490  * perform byte reordering, as necessary, for the target system to put
491  * the value in target system byte ordering, and increment the pointer
492  * by 16-bits (2 bytes).
493  *
494  * @param[inout]  p   A reference to an aligned pointer address
495  *                    to read the 16-bit big endian byte
496  *                    ordered value from and to then increment by 16-
497  *                    bits (2 bytes).
498  *
499  * @return The 16-bit value at the specified pointer address.
500  */
501 static inline uint16_t ReadAligned16(const void *&p)
502 {
503     return ByteOrder::Swap16BigToHost(IO::ReadAligned16(p));
504 }
505
506 /**
507  * Perform an aligned memory read of the big endian
508  * byte ordered 32-bit value from the specified pointer address,
509  * perform byte reordering, as necessary, for the target system to put
510  * the value in target system byte ordering, and increment the pointer
511  * by 32-bits (4 bytes).
512  *
513  * @param[inout]  p   A reference to an aligned pointer address
514  *                    to read the 32-bit big endian byte
515  *                    ordered value from and to then increment by 32-
516  *                    bits (4 bytes).
517  *
518  * @return The 32-bit value at the specified pointer address.
519  */
520 static inline uint32_t ReadAligned32(const void *&p)
521 {
522     return ByteOrder::Swap32BigToHost(IO::ReadAligned32(p));
523 }
524
525 /**
526  * Perform an aligned memory read of the big endian
527  * byte ordered 64-bit value from the specified pointer address,
528  * perform byte reordering, as necessary, for the target system to put
529  * the value in target system byte ordering, and increment the pointer
530  * by 64-bits (8 bytes).
531  *
532  * @param[inout]  p   A reference to an aligned pointer address
533  *                    to read the 64-bit big endian byte
534  *                    ordered value from and to then increment by 64-
535  *                    bits (8 bytes).
536  *
537  * @return The 64-bit value at the specified pointer address.
538  */
539 static inline uint64_t ReadAligned64(const void *&p)
540 {
541     return ByteOrder::Swap64BigToHost(IO::ReadAligned64(p));
542 }
543
544 /**
545  * Perform an aligned memory write of the target system
546  * byte ordered 8-bit value to the specified pointer address,
547  * perform byte reordering, as necessary, for the target system to
548  * put the value in big endian byte ordering.
549  *
550  * @param[inout]  p   A reference to an aligned pointer address
551  *                    to write the target system byte
552  *                    ordered 8-bit value to in big endian byte
553  *                    ordering and to then increment by 8-bits (1
554  *                    byte).
555  *
556  * @param[in]  v      The 8-bit value to write.
557  *
558  */
559 static inline void     WriteAligned8(void *&p, uint8_t v)
560 {
561     IO::WriteAligned8(p, v);
562 }
563
564 /**
565  * Perform an aligned memory write of the target system
566  * byte ordered 16-bit value to the specified pointer address,
567  * perform byte reordering, as necessary, for the target system to
568  * put the value in big endian byte ordering.
569  *
570  * @param[inout]  p   A reference to an aligned pointer address
571  *                    to write the target system byte
572  *                    ordered 16-bit value to in big endian byte
573  *                    ordering and to then increment by 16-bits (2
574  *                    bytes).
575  *
576  * @param[in]  v      The 16-bit value to write.
577  *
578  */
579 static inline void     WriteAligned16(void *&p, uint16_t v)
580 {
581     IO::WriteAligned16(p, ByteOrder::Swap16HostToBig(v));
582 }
583
584 /**
585  * Perform an aligned memory write of the target system
586  * byte ordered 32-bit value to the specified pointer address,
587  * perform byte reordering, as necessary, for the target system to
588  * put the value in big endian byte ordering.
589  *
590  * @param[inout]  p   A reference to an aligned pointer address
591  *                    to write the target system byte
592  *                    ordered 32-bit value to in big endian byte
593  *                    ordering and to then increment by 16-bits (4
594  *                    bytes).
595  *
596  * @param[in]  v      The 32-bit value to write.
597  *
598  */
599 static inline void     WriteAligned32(void *&p, uint32_t v)
600 {
601     IO::WriteAligned32(p, ByteOrder::Swap32HostToBig(v));
602 }
603
604 /**
605  * Perform an aligned memory write of the target system
606  * byte ordered 64-bit value to the specified pointer address,
607  * perform byte reordering, as necessary, for the target system to
608  * put the value in big endian byte ordering.
609  *
610  * @param[inout]  p   A reference to an aligned pointer address
611  *                    to write the target system byte
612  *                    ordered 64-bit value to in big endian byte
613  *                    ordering and to then increment by 64-bits (8
614  *                    bytes).
615  *
616  * @param[in]  v      The 64-bit value to write.
617  *
618  */
619 static inline void     WriteAligned64(void *&p, uint64_t v)
620 {
621     IO::WriteAligned64(p, ByteOrder::Swap64HostToBig(v));
622 }
623
624 /**
625  * Perform an unaligned memory read of the big endian
626  * byte ordered 8-bit value from the specified pointer address,
627  * perform byte reordering, as necessary, for the target system to
628  * put the value in target system byte ordering.
629  *
630  * @param[in]  p      An unaligned pointer address to read
631  *                    the 8-bit big endian byte ordered value from.
632  *
633  * @return The 8-bit value at the specified pointer address.
634  */
635 static inline uint8_t  GetUnaligned8(const void *p)
636 {
637     return IO::GetUnaligned8(p);
638 }
639
640 /**
641  * Perform an unaligned memory read of the big endian
642  * byte ordered 16-bit value from the specified pointer address,
643  * perform byte reordering, as necessary, for the target system to
644  * put the value in target system byte ordering.
645  *
646  * @param[in]  p      An unaligned pointer address to read
647  *                    the 16-bit big endian byte ordered value from.
648  *
649  * @return The 16-bit value at the specified pointer address.
650  */
651 static inline uint16_t GetUnaligned16(const void *p)
652 {
653     return ByteOrder::Swap16BigToHost(IO::GetUnaligned16(p));
654 }
655
656 /**
657  * Perform an unaligned memory read of the big endian
658  * byte ordered 32-bit value from the specified pointer address,
659  * perform byte reordering, as necessary, for the target system to
660  * put the value in target system byte ordering.
661  *
662  * @param[in]  p      An unaligned pointer address to read
663  *                    the 32-bit big endian byte ordered value from.
664  *
665  * @return The 32-bit value at the specified pointer address.
666  */
667 static inline uint32_t GetUnaligned32(const void *p)
668 {
669     return ByteOrder::Swap32BigToHost(IO::GetUnaligned32(p));
670 }
671
672 /**
673  * Perform an unaligned memory read of the big endian
674  * byte ordered 64-bit value from the specified pointer address,
675  * perform byte reordering, as necessary, for the target system to
676  * put the value in target system byte ordering.
677  *
678  * @param[in]  p      An unaligned pointer address to read
679  *                    the 64-bit big endian byte ordered value from.
680  *
681  * @return The 64-bit value at the specified pointer address.
682  */
683 static inline uint64_t GetUnaligned64(const void *p)
684 {
685     return ByteOrder::Swap64BigToHost(IO::GetUnaligned64(p));
686 }
687
688 /**
689  * Perform an unaligned memory write of the target system
690  * byte ordered 8-bit value to the specified pointer address,
691  * perform byte reordering, as necessary, for the target system to
692  * put the value in big endian byte ordering.
693  *
694  * @param[in]  p      An unaligned pointer address to write
695  *                    the target system byte ordered 8-bit value to in big
696  *                    endian byte ordering.
697  *
698  * @param[in]  v      The 8-bit value to write.
699  *
700  */
701 static inline void     PutUnaligned8(void *p, uint8_t v)
702 {
703     IO::PutUnaligned8(p, v);
704 }
705
706 /**
707  * Perform an unaligned memory write of the target system
708  * byte ordered 16-bit value to the specified pointer address,
709  * perform byte reordering, as necessary, for the target system to
710  * put the value in big endian byte ordering.
711  *
712  * @param[in]  p      An unaligned pointer address to write
713  *                    the target system byte ordered 16-bit value to in big
714  *                    endian byte ordering.
715  *
716  * @param[in]  v      The 16-bit value to write.
717  *
718  */
719 static inline void     PutUnaligned16(void *p, uint16_t v)
720 {
721     IO::PutUnaligned16(p, ByteOrder::Swap16HostToBig(v));
722 }
723
724 /**
725  * Perform an unaligned memory write of the target system
726  * byte ordered 32-bit value to the specified pointer address,
727  * perform byte reordering, as necessary, for the target system to
728  * put the value in big endian byte ordering.
729  *
730  * @param[in]  p      An unaligned pointer address to write
731  *                    the target system byte ordered 32-bit value to in big
732  *                    endian byte ordering.
733  *
734  * @param[in]  v      The 32-bit value to write.
735  *
736  */
737 static inline void     PutUnaligned32(void *p, uint32_t v)
738 {
739     IO::PutUnaligned32(p, ByteOrder::Swap32HostToBig(v));
740 }
741
742 /**
743  * Perform an unaligned memory write of the target system
744  * byte ordered 64-bit value to the specified pointer address,
745  * perform byte reordering, as necessary, for the target system to
746  * put the value in big endian byte ordering.
747  *
748  * @param[in]  p      An unaligned pointer address to write
749  *                    the target system byte ordered 64-bit value to in big
750  *                    endian byte ordering.
751  *
752  * @param[in]  v      The 64-bit value to write.
753  *
754  */
755 static inline void     PutUnaligned64(void *p, uint64_t v)
756 {
757     IO::PutUnaligned64(p, ByteOrder::Swap64HostToBig(v));
758 }
759
760 /**
761  * Perform an unaligned memory read of the big endian
762  * byte ordered 8-bit value from the specified pointer address,
763  * perform byte reordering, as necessary, for the target system to put
764  * the value in target system byte ordering, and increment the pointer
765  * by 8-bits (1 byte).
766  *
767  * @param[inout]  p   A reference to an unaligned pointer address
768  *                    to read the 8-bit big endian byte
769  *                    ordered value from and to then increment by 8-
770  *                    bits (1 byte).
771  *
772  * @return The 8-bit value at the specified pointer address.
773  */
774 static inline uint8_t  ReadUnaligned8(const void *&p)
775 {
776     return IO::ReadUnaligned8(p);
777 }
778
779 /**
780  * Perform an unaligned memory read of the big endian
781  * byte ordered 16-bit value from the specified pointer address,
782  * perform byte reordering, as necessary, for the target system to put
783  * the value in target system byte ordering, and increment the pointer
784  * by 16-bits (2 bytes).
785  *
786  * @param[inout]  p   A reference to an unaligned pointer address
787  *                    to read the 16-bit big endian byte
788  *                    ordered value from and to then increment by 16-
789  *                    bits (2 bytes).
790  *
791  * @return The 16-bit value at the specified pointer address.
792  */
793 static inline uint16_t ReadUnaligned16(const void *&p)
794 {
795     return ByteOrder::Swap16BigToHost(IO::ReadUnaligned16(p));
796 }
797
798 /**
799  * Perform an unaligned memory read of the big endian
800  * byte ordered 32-bit value from the specified pointer address,
801  * perform byte reordering, as necessary, for the target system to put
802  * the value in target system byte ordering, and increment the pointer
803  * by 32-bits (4 bytes).
804  *
805  * @param[inout]  p   A reference to an unaligned pointer address
806  *                    to read the 32-bit big endian byte
807  *                    ordered value from and to then increment by 32-
808  *                    bits (4 bytes).
809  *
810  * @return The 32-bit value at the specified pointer address.
811  */
812 static inline uint32_t ReadUnaligned32(const void *&p)
813 {
814     return ByteOrder::Swap32BigToHost(IO::ReadUnaligned32(p));
815 }
816
817 /**
818  * Perform an unaligned memory read of the big endian
819  * byte ordered 64-bit value from the specified pointer address,
820  * perform byte reordering, as necessary, for the target system to put
821  * the value in target system byte ordering, and increment the pointer
822  * by 64-bits (8 bytes).
823  *
824  * @param[inout]  p   A reference to an unaligned pointer address
825  *                    to read the 64-bit big endian byte
826  *                    ordered value from and to then increment by 64-
827  *                    bits (8 bytes).
828  *
829  * @return The 64-bit value at the specified pointer address.
830  */
831 static inline uint64_t ReadUnaligned64(const void *&p)
832 {
833     return ByteOrder::Swap64BigToHost(IO::ReadUnaligned64(p));
834 }
835
836 /**
837  * Perform an unaligned memory write of the target system
838  * byte ordered 8-bit value to the specified pointer address,
839  * perform byte reordering, as necessary, for the target system to
840  * put the value in big endian byte ordering.
841  *
842  * @param[inout]  p   A reference to an unaligned pointer address
843  *                    to write the target system byte
844  *                    ordered 8-bit value to in big endian byte
845  *                    ordering and to then increment by 8-bits (1
846  *                    byte).
847  *
848  * @param[in]  v      The 8-bit value to write.
849  *
850  */
851 static inline void     WriteUnaligned8(void *&p, uint8_t v)
852 {
853     IO::WriteUnaligned8(p, v);
854 }
855
856 /**
857  * Perform an unaligned memory write of the target system
858  * byte ordered 16-bit value to the specified pointer address,
859  * perform byte reordering, as necessary, for the target system to
860  * put the value in big endian byte ordering.
861  *
862  * @param[inout]  p   A reference to an unaligned pointer address
863  *                    to write the target system byte
864  *                    ordered 16-bit value to in big endian byte
865  *                    ordering and to then increment by 16-bits (2
866  *                    bytes).
867  *
868  * @param[in]  v      The 16-bit value to write.
869  *
870  */
871 static inline void     WriteUnaligned16(void *&p, uint16_t v)
872 {
873     IO::WriteUnaligned16(p, ByteOrder::Swap16HostToBig(v));
874 }
875
876 /**
877  * Perform an unaligned memory write of the target system
878  * byte ordered 32-bit value to the specified pointer address,
879  * perform byte reordering, as necessary, for the target system to
880  * put the value in big endian byte ordering.
881  *
882  * @param[inout]  p   A reference to an unaligned pointer address
883  *                    to write the target system byte
884  *                    ordered 32-bit value to in big endian byte
885  *                    ordering and to then increment by 16-bits (4
886  *                    bytes).
887  *
888  * @param[in]  v      The 32-bit value to write.
889  *
890  */
891 static inline void     WriteUnaligned32(void *&p, uint32_t v)
892 {
893     IO::WriteUnaligned32(p, ByteOrder::Swap32HostToBig(v));
894 }
895
896 /**
897  * Perform an unaligned memory write of the target system
898  * byte ordered 64-bit value to the specified pointer address,
899  * perform byte reordering, as necessary, for the target system to
900  * put the value in big endian byte ordering.
901  *
902  * @param[inout]  p   A reference to an unaligned pointer address
903  *                    to write the target system byte
904  *                    ordered 64-bit value to in big endian byte
905  *                    ordering and to then increment by 64-bits (8
906  *                    bytes).
907  *
908  * @param[in]  v      The 64-bit value to write.
909  *
910  */
911 static inline void     WriteUnaligned64(void *&p, uint64_t v)
912 {
913     IO::WriteUnaligned64(p, ByteOrder::Swap64HostToBig(v));
914 }
915
916 } // namespace BigEndian
917
918 } // namespace IO
919
920 } // namespace nl
921
922 #endif // NLIO_BYTEORDER_BIG_HPP