Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
endian.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Roc Streaming authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_core/endian.h
10 //! @brief Endian conversion functions.
11 
12 #ifndef ROC_CORE_ENDIAN_H_
13 #define ROC_CORE_ENDIAN_H_
14 
15 // This file provides explicitly-sized conveniently named short-hands
16 // for endian conversion functions.
17 
18 #include "roc_core/endian_ops.h"
19 
20 namespace roc {
21 namespace core {
22 
23 //! Network to host byte order (unsigned 16-bit).
24 inline uint16_t ntoh16u(uint16_t v) {
25  return EndianOps::swap_native_be(v);
26 }
27 
28 //! Network to host byte order (signed 16-bit).
29 inline int16_t ntoh16s(int16_t v) {
30  return EndianOps::swap_native_be(v);
31 }
32 
33 //! Network to host byte order (unsigned 32-bit).
34 inline uint32_t ntoh32u(uint32_t v) {
35  return EndianOps::swap_native_be(v);
36 }
37 
38 //! Network to host byte order (signed 32-bit).
39 inline int32_t ntoh32s(int32_t v) {
40  return EndianOps::swap_native_be(v);
41 }
42 
43 //! Network to host byte order (unsigned 64-bit).
44 inline uint64_t ntoh64u(uint64_t v) {
45  return EndianOps::swap_native_be(v);
46 }
47 
48 //! Network to host byte order (signed 64-bit).
49 inline int64_t ntoh64s(int64_t v) {
50  return EndianOps::swap_native_be(v);
51 }
52 
53 //! Host to network byte order (unsigned 16-bit).
54 inline uint16_t hton16u(uint16_t v) {
55  return EndianOps::swap_native_be(v);
56 }
57 
58 //! Host to network byte order (signed 16-bit).
59 inline int16_t hton16s(int16_t v) {
60  return EndianOps::swap_native_be(v);
61 }
62 
63 //! Host to network byte order (unsigned 32-bit).
64 inline uint32_t hton32u(uint32_t v) {
65  return EndianOps::swap_native_be(v);
66 }
67 
68 //! Host to network byte order (signed 32-bit).
69 inline int32_t hton32s(int32_t v) {
70  return EndianOps::swap_native_be(v);
71 }
72 
73 //! Host to network byte order (unsigned 64-bit).
74 inline uint64_t hton64u(uint64_t v) {
75  return EndianOps::swap_native_be(v);
76 }
77 
78 //! Host to network byte order (signed 64-bit).
79 inline int64_t hton64s(int64_t v) {
80  return EndianOps::swap_native_be(v);
81 }
82 
83 } // namespace core
84 } // namespace roc
85 
86 #endif // ROC_CORE_ENDIAN_H_
static T swap_native_be(T v)
Swap between native endian and big endian.
Definition: endian_ops.h:31
Endian operations.
int32_t hton32s(int32_t v)
Host to network byte order (signed 32-bit).
Definition: endian.h:69
uint16_t hton16u(uint16_t v)
Host to network byte order (unsigned 16-bit).
Definition: endian.h:54
int32_t ntoh32s(int32_t v)
Network to host byte order (signed 32-bit).
Definition: endian.h:39
int16_t hton16s(int16_t v)
Host to network byte order (signed 16-bit).
Definition: endian.h:59
uint64_t hton64u(uint64_t v)
Host to network byte order (unsigned 64-bit).
Definition: endian.h:74
uint16_t ntoh16u(uint16_t v)
Network to host byte order (unsigned 16-bit).
Definition: endian.h:24
int64_t ntoh64s(int64_t v)
Network to host byte order (signed 64-bit).
Definition: endian.h:49
uint64_t ntoh64u(uint64_t v)
Network to host byte order (unsigned 64-bit).
Definition: endian.h:44
uint32_t hton32u(uint32_t v)
Host to network byte order (unsigned 32-bit).
Definition: endian.h:64
int64_t hton64s(int64_t v)
Host to network byte order (signed 64-bit).
Definition: endian.h:79
int16_t ntoh16s(int16_t v)
Network to host byte order (signed 16-bit).
Definition: endian.h:29
uint32_t ntoh32u(uint32_t v)
Network to host byte order (unsigned 32-bit).
Definition: endian.h:34
Root namespace.