Ocean
Loading...
Searching...
No Matches
Data.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef FACEBOOK_NETWORK_DATA_H
9#define FACEBOOK_NETWORK_DATA_H
10
12
13namespace Ocean
14{
15
16namespace Network
17{
18
19/**
20 * This class provides function handling different network data.
21 * @ingroup network
22 */
23class OCEAN_NETWORK_EXPORT Data
24{
25 public:
26
27 /**
28 * Definition of different order types.
29 */
30 enum OrderType : uint32_t
31 {
32 /// Big endian type.
34 /// Little endian type.
36 /// Readable endian type which is platform specific.
37 TYPE_READABLE
38 };
39
40 public:
41
42 /**
43 * Returns a value in big-endian order given in local system bit order.<br>
44 * E.g. local system order on Windows platforms is little-endian.
45 * @param value The value to translate
46 * @return Translated value in bit-endian order
47 */
48 static inline int toBigEndian(const int32_t value);
49
50 /**
51 * Returns a value in big-endian order given in local system bit order.<br>
52 * E.g. local system order on Windows platforms is little-endian.
53 * @param value The value to translate
54 * @return Translated value in bit-endian order
55 */
56 static inline uint32_t toBigEndian(const uint32_t value);
57
58 /**
59 * Returns a value in big-endian order given in local system bit order.<br>
60 * E.g. local system order on Windows platforms is little-endian.
61 * @param value The value to translate
62 * @return Translated value in bit-endian order
63 */
64 static inline int16_t toBigEndian(const int16_t value);
65
66 /**
67 * Returns a value in big-endian order given in local system bit order.<br>
68 * E.g. local system order on Windows platforms is little-endian.
69 * @param value The value to translate
70 * @return Translated value in bit-endian order
71 */
72 static inline uint16_t toBigEndian(const uint16_t value);
73
74 /**
75 * Returns a value in local system bit order given as big-endian bit order.<br>
76 * E.g. local system bit order on windows platforms is little-endian.
77 * @param value The value to translate
78 * @return Translated value
79 */
80 static inline int32_t fromBigEndian(const int32_t value);
81
82 /**
83 * Returns a value in local system bit order given as big-endian bit order.<br>
84 * E.g. local system bit order on windows platforms is little-endian.
85 * @param value The value to translate
86 * @return Translated value
87 */
88 static inline uint32_t fromBigEndian(const uint32_t value);
89
90 /**
91 * Returns a value in local system bit order given as big-endian bit order.<br>
92 * E.g. local system bit order on windows platforms is little-endian.<br>
93 * @param value The value to translate
94 * @return Translated value
95 */
96 static inline int16_t fromBigEndian(const int16_t value);
97
98 /**
99 * Returns a value in local system bit order given as big-endian bit order.<br>
100 * E.g. local system bit order on windows platforms is little-endian.<br>
101 * @param value The value to translate
102 * @return Translated value
103 */
104 static inline uint16_t fromBigEndian(const uint16_t value);
105};
106
107inline int Data::toBigEndian(const int32_t value)
108{
109 return toBigEndian(uint32_t(value));
110}
111
112inline uint32_t Data::toBigEndian(const uint32_t value)
113{
114#ifdef OCEAN_LITTLE_ENDIAN
115 return (value >> 24u) | ((value >> 8u) & 0xFF00u) | ((value << 8u) & 0xFF0000u) | (value << 24u);
116#else
117 return value;
118#endif
119}
120
121inline int16_t Data::toBigEndian(const int16_t value)
122{
123 return toBigEndian(uint16_t(value));
124}
125
126inline uint16_t Data::toBigEndian(const uint16_t value)
127{
128#ifdef OCEAN_LITTLE_ENDIAN
129 return uint16_t((value >> 8u) | (value << 8u));
130#else
131 return value;
132#endif
133}
134
135inline int32_t Data::fromBigEndian(const int32_t value)
136{
137 return fromBigEndian(uint32_t(value));
138}
139
140inline uint32_t Data::fromBigEndian(const uint32_t value)
141{
142#ifdef OCEAN_LITTLE_ENDIAN
143 return (value >> 24u) | ((value >> 8u) & 0xFF00u) | ((value << 8u) & 0xFF0000u) | (value << 24u);
144#else
145 return value;
146#endif
147}
148
149inline int16_t Data::fromBigEndian(const int16_t value)
150{
151 return fromBigEndian(uint16_t(value));
152}
153
154inline uint16_t Data::fromBigEndian(const uint16_t value)
155{
156#ifdef OCEAN_LITTLE_ENDIAN
157 return uint16_t((value >> 8u) | (value << 8u));
158#else
159 return value;
160#endif
161}
162
163}
164
165}
166
167#endif // FACEBOOK_NETWORK_DATA_H
This class provides function handling different network data.
Definition Data.h:24
static int toBigEndian(const int32_t value)
Returns a value in big-endian order given in local system bit order.
Definition Data.h:107
OrderType
Definition of different order types.
Definition Data.h:31
@ TYPE_BIG_ENDIAN
Big endian type.
Definition Data.h:33
@ TYPE_LITTLE_ENDIAN
Little endian type.
Definition Data.h:35
static int32_t fromBigEndian(const int32_t value)
Returns a value in local system bit order given as big-endian bit order.
Definition Data.h:135
The namespace covering the entire Ocean framework.
Definition Accessor.h:15