Skip to content

Commit 575e1dd

Browse files
committed
moved network fuctions from header to cpp file
1 parent b8389b3 commit 575e1dd

File tree

2 files changed

+60
-55
lines changed

2 files changed

+60
-55
lines changed

include/DMDUtil/DMD.h

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -129,43 +129,8 @@ class DMDUTILAPI DMD
129129
uint16_t width;
130130
uint16_t height;
131131

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-
}
132+
void convertToHostByteOrder();
133+
Update toNetworkByteOrder() const;
169134
};
170135

171136
struct StreamHeader
@@ -179,23 +144,8 @@ class DMDUTILAPI DMD
179144
uint8_t disconnectOthers = 0; // 0 => no, 1 => yes
180145
uint32_t length = 0;
181146

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-
}
147+
void convertToHostByteOrder();
148+
void convertToNetworkByteOrder();
199149
};
200150

201151
struct PathsHeader
@@ -206,7 +156,6 @@ class DMDUTILAPI DMD
206156
char pupVideosPath[DMDUTIL_MAX_PATH_SIZE] = {0};
207157

208158
void convertToHostByteOrder() {}
209-
210159
void convertToNetworkByteOrder() {}
211160
};
212161
#pragma pack(pop) // Reset to default packing

src/DMD.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,62 @@ class DMDServerConnector
7171

7272
bool DMD::m_finding = false;
7373

74+
void DMD::Update::convertToHostByteOrder()
75+
{
76+
// uint8_t and bool are not converted, as they are already in host byte order.
77+
mode = static_cast<Mode>(ntohl(static_cast<uint32_t>(mode)));
78+
layout = static_cast<AlphaNumericLayout>(ntohl(static_cast<uint32_t>(layout)));
79+
depth = ntohl(depth);
80+
for (size_t i = 0; i < 256 * 64; i++)
81+
{
82+
segData[i] = ntohs(segData[i]);
83+
}
84+
for (size_t i = 0; i < 128; i++)
85+
{
86+
segData2[i] = ntohs(segData2[i]);
87+
}
88+
width = ntohs(width);
89+
height = ntohs(height);
90+
}
91+
92+
DMD::Update DMD::Update::toNetworkByteOrder() const
93+
{
94+
// uint8_t and bool are not converted, as they are already in network byte order.
95+
Update copy = *this;
96+
copy.mode = static_cast<Mode>(htonl(static_cast<uint32_t>(mode)));
97+
copy.layout = static_cast<AlphaNumericLayout>(htonl(static_cast<uint32_t>(layout)));
98+
copy.depth = htonl(depth);
99+
for (size_t i = 0; i < 256 * 64; i++)
100+
{
101+
copy.segData[i] = htons(segData[i]);
102+
}
103+
for (size_t i = 0; i < 128; i++)
104+
{
105+
copy.segData2[i] = htons(segData2[i]);
106+
}
107+
copy.width = htons(width);
108+
copy.height = htons(height);
109+
return copy;
110+
}
111+
112+
void DMD::StreamHeader::convertToHostByteOrder()
113+
{
114+
// uint8_t and char are not converted, as they are already in host byte order.
115+
mode = static_cast<Mode>(ntohl(static_cast<uint32_t>(mode)));
116+
width = ntohs(width);
117+
height = ntohs(height);
118+
length = ntohl(length);
119+
}
120+
121+
void DMD::StreamHeader::convertToNetworkByteOrder()
122+
{
123+
// uint8_t and char are not converted, as they are already in network byte order.
124+
mode = static_cast<Mode>(htonl(static_cast<uint32_t>(mode)));
125+
width = htons(width);
126+
height = htons(height);
127+
length = htonl(length);
128+
}
129+
74130
DMD::DMD()
75131
{
76132
for (uint8_t i = 0; i < DMDUTIL_FRAME_BUFFER_SIZE; i++)

0 commit comments

Comments
 (0)