1515#define DMDUTIL_MAX_PATH_SIZE 256
1616#define DMDUTIL_MAX_TRANSITIONAL_FRAME_DURATION 25
1717
18+ #if defined(_WIN32) || defined(_WIN64)
19+ #include < winsock2.h> // Windows byte-order functions
20+ #else
21+ #include < arpa/inet.h> // Linux/macOS byte-order functions
22+ #endif
23+
1824#include < atomic>
1925#include < condition_variable>
2026#include < cstdint>
@@ -122,6 +128,44 @@ class DMDUTILAPI DMD
122128 uint8_t b;
123129 uint16_t width;
124130 uint16_t height;
131+
132+ void convertToHostByteOrder ()
133+ {
134+ // uint8_t and bool are not converted, as they are already in host byte order.
135+ mode = static_cast <Mode>(ntohl (static_cast <uint32_t >(mode)));
136+ layout = static_cast <AlphaNumericLayout>(ntohl (static_cast <uint32_t >(layout)));
137+ depth = ntohl (depth);
138+ for (size_t i = 0 ; i < 256 * 64 ; i++)
139+ {
140+ segData[i] = ntohs (segData[i]);
141+ }
142+ for (size_t i = 0 ; i < 128 ; i++)
143+ {
144+ segData2[i] = ntohs (segData2[i]);
145+ }
146+ width = ntohs (width);
147+ height = ntohs (height);
148+ }
149+
150+ Update toNetworkByteOrder () const
151+ {
152+ // uint8_t and bool are not converted, as they are already in network byte order.
153+ Update copy = *this ;
154+ copy.mode = static_cast <Mode>(htonl (static_cast <uint32_t >(mode)));
155+ copy.layout = static_cast <AlphaNumericLayout>(htonl (static_cast <uint32_t >(layout)));
156+ copy.depth = htonl (depth);
157+ for (size_t i = 0 ; i < 256 * 64 ; i++)
158+ {
159+ copy.segData [i] = htons (segData[i]);
160+ }
161+ for (size_t i = 0 ; i < 128 ; i++)
162+ {
163+ copy.segData2 [i] = htons (segData2[i]);
164+ }
165+ copy.width = htons (width);
166+ copy.height = htons (height);
167+ return copy;
168+ }
125169 };
126170
127171 struct StreamHeader
@@ -134,6 +178,24 @@ class DMDUTILAPI DMD
134178 uint8_t buffered = 0 ; // 0 => unbuffered, 1 => buffered
135179 uint8_t disconnectOthers = 0 ; // 0 => no, 1 => yes
136180 uint32_t length = 0 ;
181+
182+ void convertToHostByteOrder ()
183+ {
184+ // uint8_t and char are not converted, as they are already in host byte order.
185+ mode = static_cast <Mode>(ntohl (static_cast <uint32_t >(mode)));
186+ width = ntohs (width);
187+ height = ntohs (height);
188+ length = ntohl (length);
189+ }
190+
191+ void convertToNetworkByteOrder ()
192+ {
193+ // uint8_t and char are not converted, as they are already in network byte order.
194+ mode = static_cast <Mode>(htonl (static_cast <uint32_t >(mode)));
195+ width = htons (width);
196+ height = htons (height);
197+ length = htonl (length);
198+ }
137199 };
138200
139201 struct PathsHeader
@@ -142,6 +204,10 @@ class DMDUTILAPI DMD
142204 char name[DMDUTIL_MAX_NAME_SIZE] = {0 };
143205 char altColorPath[DMDUTIL_MAX_PATH_SIZE] = {0 };
144206 char pupVideosPath[DMDUTIL_MAX_PATH_SIZE] = {0 };
207+
208+ void convertToHostByteOrder () {}
209+
210+ void convertToNetworkByteOrder () {}
145211 };
146212#pragma pack(pop) // Reset to default packing
147213
0 commit comments