Mercurial > hg > piper-cpp
comparison utilities/vampipe-convert.cpp @ 44:a98ef4c2616b
Make base64/text selectable when serialising process and feature blocks; add base64 version as an output format for vampipe-convert; make VamPipePluginLibrary switch to returning base64 encoding as soon as it is fed any as input
author | Chris Cannam <c.cannam@qmul.ac.uk> |
---|---|
date | Thu, 08 Sep 2016 15:27:48 +0100 |
parents | 91f5c92d3bf7 |
children | f4244a2d55ac |
comparison
equal
deleted
inserted
replaced
43:62c17e143aba | 44:a98ef4c2616b |
---|---|
22 " " << myname << " [-i <informat>] [-o <outformat>] response\n\n" | 22 " " << myname << " [-i <informat>] [-o <outformat>] response\n\n" |
23 " where\n" | 23 " where\n" |
24 " <informat>: the format to read from stdin\n" | 24 " <informat>: the format to read from stdin\n" |
25 " (\"json\" or \"capnp\", default is \"json\")\n" | 25 " (\"json\" or \"capnp\", default is \"json\")\n" |
26 " <outformat>: the format to convert to and write to stdout\n" | 26 " <outformat>: the format to convert to and write to stdout\n" |
27 " (\"json\" or \"capnp\", default is \"json\")\n" | 27 " (\"json\", \"json-b64\" or \"capnp\", default is \"json\")\n" |
28 " request|response: whether to expect Vamp request or response messages\n\n" | 28 " request|response: whether messages are Vamp request or response type\n\n" |
29 "If <informat> and <outformat> differ, convert from <informat> to <outformat>.\n" | 29 "If <informat> and <outformat> differ, convert from <informat> to <outformat>.\n" |
30 "If <informat> and <outformat> are the same, just check validity of incoming\n" | 30 "If <informat> and <outformat> are the same, just check validity of incoming\n" |
31 "messages and pass them to output.\n\n"; | 31 "messages and pass them to output.\n\n" |
32 "Specifying \"json-b64\" as output format forces base64 encoding for process and\n" | |
33 "feature blocks, unlike the \"json\" output format which uses text encoding.\n" | |
34 "The \"json\" input format accepts either.\n\n"; | |
32 | 35 |
33 exit(2); | 36 exit(2); |
34 } | 37 } |
35 | 38 |
36 Json | 39 Json |
91 } | 94 } |
92 | 95 |
93 Json j = convertRequestJson(input); | 96 Json j = convertRequestJson(input); |
94 | 97 |
95 rr.type = VampJson::getRequestResponseType(j); | 98 rr.type = VampJson::getRequestResponseType(j); |
99 VampJson::BufferSerialisation serialisation = VampJson::BufferSerialisation::Text; | |
96 | 100 |
97 switch (rr.type) { | 101 switch (rr.type) { |
98 | 102 |
99 case RRType::List: | 103 case RRType::List: |
100 VampJson::toVampRequest_List(j); // type check only | 104 VampJson::toVampRequest_List(j); // type check only |
104 break; | 108 break; |
105 case RRType::Configure: | 109 case RRType::Configure: |
106 rr.configurationRequest = VampJson::toVampRequest_Configure(j, mapper); | 110 rr.configurationRequest = VampJson::toVampRequest_Configure(j, mapper); |
107 break; | 111 break; |
108 case RRType::Process: | 112 case RRType::Process: |
109 rr.processRequest = VampJson::toVampRequest_Process(j, mapper); | 113 rr.processRequest = VampJson::toVampRequest_Process(j, mapper, serialisation); |
110 break; | 114 break; |
111 case RRType::Finish: | 115 case RRType::Finish: |
112 rr.finishPlugin = VampJson::toVampRequest_Finish(j, mapper); | 116 rr.finishPlugin = VampJson::toVampRequest_Finish(j, mapper); |
113 break; | 117 break; |
114 case RRType::NotValid: | 118 case RRType::NotValid: |
117 | 121 |
118 return rr; | 122 return rr; |
119 } | 123 } |
120 | 124 |
121 void | 125 void |
122 writeRequestJson(RequestOrResponse &rr) | 126 writeRequestJson(RequestOrResponse &rr, bool useBase64) |
123 { | 127 { |
124 Json j; | 128 Json j; |
125 | 129 |
126 switch (rr.type) { | 130 switch (rr.type) { |
127 | 131 |
133 break; | 137 break; |
134 case RRType::Configure: | 138 case RRType::Configure: |
135 j = VampJson::fromVampRequest_Configure(rr.configurationRequest, mapper); | 139 j = VampJson::fromVampRequest_Configure(rr.configurationRequest, mapper); |
136 break; | 140 break; |
137 case RRType::Process: | 141 case RRType::Process: |
138 j = VampJson::fromVampRequest_Process(rr.processRequest, mapper); | 142 j = VampJson::fromVampRequest_Process |
143 (rr.processRequest, mapper, | |
144 useBase64 ? | |
145 VampJson::BufferSerialisation::Base64 : | |
146 VampJson::BufferSerialisation::Text); | |
139 break; | 147 break; |
140 case RRType::Finish: | 148 case RRType::Finish: |
141 j = VampJson::fromVampRequest_Finish(rr.finishPlugin, mapper); | 149 j = VampJson::fromVampRequest_Finish(rr.finishPlugin, mapper); |
142 break; | 150 break; |
143 case RRType::NotValid: | 151 case RRType::NotValid: |
160 } | 168 } |
161 | 169 |
162 Json j = convertResponseJson(input); | 170 Json j = convertResponseJson(input); |
163 | 171 |
164 rr.type = VampJson::getRequestResponseType(j); | 172 rr.type = VampJson::getRequestResponseType(j); |
173 VampJson::BufferSerialisation serialisation = VampJson::BufferSerialisation::Text; | |
165 | 174 |
166 switch (rr.type) { | 175 switch (rr.type) { |
167 | 176 |
168 case RRType::List: | 177 case RRType::List: |
169 rr.listResponse = VampJson::toVampResponse_List(j); | 178 rr.listResponse = VampJson::toVampResponse_List(j); |
173 break; | 182 break; |
174 case RRType::Configure: | 183 case RRType::Configure: |
175 rr.configurationResponse = VampJson::toVampResponse_Configure(j); | 184 rr.configurationResponse = VampJson::toVampResponse_Configure(j); |
176 break; | 185 break; |
177 case RRType::Process: | 186 case RRType::Process: |
178 rr.processResponse = VampJson::toVampResponse_Process(j); | 187 rr.processResponse = VampJson::toVampResponse_Process(j, serialisation); |
179 break; | 188 break; |
180 case RRType::Finish: | 189 case RRType::Finish: |
181 rr.finishResponse = VampJson::toVampResponse_Finish(j); | 190 rr.finishResponse = VampJson::toVampResponse_Finish(j, serialisation); |
182 break; | 191 break; |
183 case RRType::NotValid: | 192 case RRType::NotValid: |
184 break; | 193 break; |
185 } | 194 } |
186 | 195 |
187 return rr; | 196 return rr; |
188 } | 197 } |
189 | 198 |
190 void | 199 void |
191 writeResponseJson(RequestOrResponse &rr) | 200 writeResponseJson(RequestOrResponse &rr, bool useBase64) |
192 { | 201 { |
193 Json j; | 202 Json j; |
194 | 203 |
195 switch (rr.type) { | 204 switch (rr.type) { |
196 | 205 |
202 break; | 211 break; |
203 case RRType::Configure: | 212 case RRType::Configure: |
204 j = VampJson::fromVampResponse_Configure(rr.configurationResponse); | 213 j = VampJson::fromVampResponse_Configure(rr.configurationResponse); |
205 break; | 214 break; |
206 case RRType::Process: | 215 case RRType::Process: |
207 j = VampJson::fromVampResponse_Process(rr.processResponse); | 216 j = VampJson::fromVampResponse_Process |
208 break; | 217 (rr.processResponse, |
209 case RRType::Finish: | 218 useBase64 ? |
210 j = VampJson::fromVampResponse_Finish(rr.finishResponse); | 219 VampJson::BufferSerialisation::Base64 : |
220 VampJson::BufferSerialisation::Text); | |
221 break; | |
222 case RRType::Finish: | |
223 j = VampJson::fromVampResponse_Finish | |
224 (rr.finishResponse, | |
225 useBase64 ? | |
226 VampJson::BufferSerialisation::Base64 : | |
227 VampJson::BufferSerialisation::Text); | |
211 break; | 228 break; |
212 case RRType::NotValid: | 229 case RRType::NotValid: |
213 break; | 230 break; |
214 } | 231 } |
215 | 232 |
391 void | 408 void |
392 writeOutput(string format, RequestOrResponse &rr) | 409 writeOutput(string format, RequestOrResponse &rr) |
393 { | 410 { |
394 if (format == "json") { | 411 if (format == "json") { |
395 if (rr.direction == RequestOrResponse::Request) { | 412 if (rr.direction == RequestOrResponse::Request) { |
396 writeRequestJson(rr); | 413 writeRequestJson(rr, false); |
397 } else { | 414 } else { |
398 writeResponseJson(rr); | 415 writeResponseJson(rr, false); |
416 } | |
417 } else if (format == "json-b64") { | |
418 if (rr.direction == RequestOrResponse::Request) { | |
419 writeRequestJson(rr, true); | |
420 } else { | |
421 writeResponseJson(rr, true); | |
399 } | 422 } |
400 } else if (format == "capnp") { | 423 } else if (format == "capnp") { |
401 if (rr.direction == RequestOrResponse::Request) { | 424 if (rr.direction == RequestOrResponse::Request) { |
402 writeRequestCapnp(rr); | 425 writeRequestCapnp(rr); |
403 } else { | 426 } else { |