I will implement a web app using CppCMS framework. Yes, it's a C++ framework.
The basic idea is to generate the binary stream, send it via response to browser, set the content type to
application/x-protobuf.
This post doesn't describe the usage of CppCMS. Please refer to cppcms.com if needed.
In web service constructor, map the url request to test_group member function.
dispatcher().assign("/testGroup" , &kaimei_web_site::test_group , this);
Some part  of test_group codes list here:
void kaimei_web_site::test_group() {
  kaimei::response res;
  try {
    ....
    response().content_type("application/x-protobuf");
    freebird::group g;
    g.set_id("1");
    g.set_name("a");
    g.set_description("d");
    g.set_device_number("5");
    g.SerializePartialToOstream(&response().out());
  } catch(std::exception const& ex) {
    ...
  }
}
That's all. Now launch browser, access the web site using /testGroup path. Browser will download a file called testGroup.
Unfortunately, the protojs can't parse the stream transferred from server.
Chrome always says:ArrayBuffer values are deprecated ...
I will update this post later.
 
No comments:
Post a Comment