File tree Expand file tree Collapse file tree 3 files changed +28
-7
lines changed
Expand file tree Collapse file tree 3 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -223,6 +223,18 @@ class AnimationData {
223223 std::cerr << " Bad type for spacing" << data[" spacing" ].type_name () << std::endl;
224224 }
225225
226+ std::string colorsString () {
227+ std::string cols = " [" ;
228+
229+ for (auto c : colors) {
230+ cols.append (c.colorsString (true ));
231+ cols.append (" ," );
232+ }
233+ if (!colors.empty ())
234+ cols.pop_back ();
235+ cols.append (" ]" );
236+ return cols;
237+ }
226238
227239 int json (char ** buff) const {
228240 std::string data = " DATA:{" ;
Original file line number Diff line number Diff line change @@ -155,7 +155,7 @@ class AnimationSender {
155155
156156 int connect () {
157157 if (::connect (socket_desc, (struct sockaddr *) &sa, sizeof (sa)) < 0 ) {
158- perror (" connect()" );
158+ perror ((host_name + " " + std::to_string (port_num) + " connect()" ). c_str () );
159159 return -1 ;
160160 }
161161 return 0 ;
Original file line number Diff line number Diff line change @@ -52,16 +52,25 @@ class ColorContainer {
5252 std::cerr << " Bad type for ColorContainer colors" << data[" colors" ].type_name () << std::endl;
5353 }
5454
55- int json (char ** buff) {
56- std::string data = R"( {"colors":[)" ;
57-
55+ std::string colorsString (bool hex = false ) {
56+ std::string data = " [" ;
5857 for (auto c : colors) {
59- data.append (std::to_string (c));
60- data.append (" ," );
58+ std::stringstream ss;
59+ if (hex) ss << " 0x" << std::hex;
60+ ss << c << " ," ;
61+ data.append (ss.str ());
6162 }
6263 if (!colors.empty ())
6364 data.pop_back ();
64- data.append (" ]}" );
65+ data.append (" ]" );
66+ return data;
67+ }
68+
69+ int json (char ** buff) {
70+ std::string data = R"( {"colors":)" ;
71+
72+ data.append (colorsString (false ));
73+ data.append (" }" );
6574
6675 strcpy (*buff, data.c_str ());
6776 return data.size ();
You can’t perform that action at this time.
0 commit comments