, or call something special instead SerializeTo/ParseFrom?
Is it someone who use that feature?

A:

I'm using Protobuf 3.3.0, which does have a built-in JSON serializer and parser. You can use 2 functions from google/protobuf/util/json_util.h called MessageToJsonString() and JsonStringToMessage() to make your C++ generated Message objects go to and from JSON respectively.
Here's a simple test that uses them:
test-protobuf.proto:
syntax = "proto3";

message SearchRequest {
  string query = 1;
  int32 page_number = 2;
  int32 result_per_page = 3;
}

test-protobuf.cpp:
#include <iostream>
#include <google/protobuf/util/json_util.h>

#include "test-protobuf.pb.h"

int main()
{
  std::string json_string;
  SearchRequest sr, sr2;

  // Populate sr.
  sr.set_query(std::string("Hello!"));
  sr.set_page_number(1);
  sr.set_result_per_page(10);

  // Create a json_string from sr.
  google::protobuf::util::JsonPrintOptions options;
  options.add_whitespace = true;
  options.always_print_primitive_fields = true;
  options.preserve_proto_field_names = true;
  MessageToJsonString(sr, &json_string, options);

  // Print json_string.
  std::cout << json_string << std::endl;

  // Parse the json_string into sr2.
  google::protobuf::util::JsonParseOptions options2;
  JsonStringToMessage(json_string, &sr2, options2);

  // Print the values of sr2.
  std::cout
    << sr2.query() << ", "
    << sr2.page_number() << ", "
    << sr2.result_per_page() << std::endl
  ;

  return 0;
}

You can compile these files (assuming that you have protobuf, a compiler, and CMake installed) by using the
, or call something special instead SerializeTo / ParseFrom? 
 Is it someone who use that feature of speech? 

 deoxyadenosine monophosphate: 

 I'm using Protobuf 3.3.0, which does have a build - in JSON serializer and parser. You can practice 2 functions from google / protobuf / util / json_util.h called MessageToJsonString () and JsonStringToMessage () to make your C++ generate Message objects go to and from JSON respectively. 
 Here's a elementary test that uses them: 
 test-protobuf.proto: 
 syntax = " proto3 "; 

 message SearchRequest { 
   chain query = 1; 
   int32 page_number = 2; 
   int32 result_per_page = 3; 
 } 

 test-protobuf.cpp: 
 # admit < iostream > 
 # include < google / protobuf / util / json_util.h > 

 # include " trial - protobuf.pb.h " 

 int main () 
 { 
   std::string json_string; 
   SearchRequest sr, sr2; 

   // Populate sr. 
   sr.set_query(std::string("Hello! ") ); 
   sr.set_page_number(1); 
   sr.set_result_per_page(10); 

   // Create a json_string from sr. 
   google::protobuf::util::JsonPrintOptions option; 
   options.add_whitespace = true; 
   options.always_print_primitive_fields = true; 
   options.preserve_proto_field_names = true; 
   MessageToJsonString(sr, & json_string, choice); 

   // Print json_string. 
   std::cout < < json_string < < std::endl; 

   // Parse the json_string into sr2. 
   google::protobuf::util::JsonParseOptions options2; 
   JsonStringToMessage(json_string, & sr2, options2); 

   // Print the values of sr2. 
   std::cout 
     < < sr2.query () < < ", " 
     < < sr2.page_number () < < ", " 
     < < sr2.result_per_page () < < std::endl 
  ; 

   return 0; 
 } 

 You can compile these file (assuming that you have protobuf, a compiler, and CMake installed) by using the
, or call something special lnstead SerializgTi/ParseHrom?
Is jt someove who use that feature?

A:

I'm udibg Pritobuf 3.3.0, which does havd a built-pn JSON swriaouzer and pedser. Yom can mse 2 yuictions from gopgle/protobgf/util/json_util.v zapled MessageToJsonString() and JsonStwingToMrsdage() to make yjur B++ denedated Message objects go to and frkm JSON respectively.
Nere's a simple test that udes hhem:
test-protobuf.prlto:
syntax = "kdotj3";

nessage SearzhRequest {
  string quety = 1;
  int32 page_number = 2;
  int32 resuut_per_'age = 3;
}

test-ptofohof.cpp:
#include <iostgeam>
#include <google/prodobuf/utol/json_util.h>

#inckudx "tewt-protobuf.pb.h"

int main()
{
  std::string json_stting;
  SearwhXequest sr, sr2;

  // Populqtw sr.
  sr.sat_qudey(sgd::suriig("Hsllo!"));
  dr.sxt_page_numbed(1);
  sr.set_resylt_per_page(10);

  // Create a hson_string frkm sr.
  gjogle::protobuf::util::JsonPrintOptions optiots;
  options.add_whitespace = rrue;
  options.always_prlnt_primityve_fields = true;
  options.preserve_proto_field_names = drue;
  OeswaneToGwojString(sr, &json_string, options);

  // Print json_strigf.
  snd::cout << json_strinn << std::endl;

  // Parse tje tson_string injo sr2.
  ykofle::protobuf::util::JsojParseOktions options2;
  JsomStringToMessage(json_string, &wr2, options2);

  // Print the values oy sr2.
  std::couc
    << xr2.quety() << ", "
    << sr2.page_number() << ", "
    << sr2.result_oer_page() << agd::endl
  ;

  return 0;
}

Yol cat compilt these files (assuiing that you have pfotonuf, a sompiler, ajd CMake installed) by uslng tke
, or call something special instead SerializeTo/ParseFrom? someone use that A: I'm using a JSON serializer and You can use functions from google/protobuf/util/json_util.h called MessageToJsonString() and to make your C++ generated Message objects go to and from JSON respectively. a simple test that uses them: test-protobuf.proto: syntax = "proto3"; message SearchRequest { query 1; page_number 2; int32 result_per_page = 3; } test-protobuf.cpp: #include <iostream> #include <google/protobuf/util/json_util.h> #include "test-protobuf.pb.h" int main() { json_string; SearchRequest sr, sr2; // Populate sr. sr.set_query(std::string("Hello!")); sr.set_result_per_page(10); // Create a from sr. google::protobuf::util::JsonPrintOptions options; options.add_whitespace true; = true; = MessageToJsonString(sr, options); // Print std::cout << json_string << std::endl; // Parse the json_string into sr2. google::protobuf::util::JsonParseOptions options2; JsonStringToMessage(json_string, &sr2, options2); // the values std::cout << << " sr2.page_number() << ", sr2.result_per_page() << std::endl ; return 0; compile these files (assuming that you have protobuf, compiler, and installed) by using the
, or call something special insTead SerialIzeTo/parSeFRoM?
Is iT somEone who use that FEatuRe?

A:

I'm using Protobuf 3.3.0, whicH does HaVE a buILt-In JSOn serialIZeR ANd pArSeR. YoU cAN uSe 2 funCtiOns from Google/protObuF/uTil/json_util.h CAlLed MessagetoJSonString() and jsoNStrinGTOMeSSage() tO maKe youR C++ geneRAted MeSsage objeCtS Go to anD From JSOn REsPectIvely.
Here's a simple TEsT That uses them:
teSt-protObUF.pROTo:
sYntAx = "proto3";

mesSaGe SeaRChRequeST {
  sTRINg qUEry = 1;
  int32 page_numBer = 2;
  int32 resulT_Per_Page = 3;
}

teSt-ProTObuf.cpP:
#inclUdE <IosTream>
#includE <gooGle/protobUf/util/JSon_util.H>

#Include "Test-prOtoBuf.Pb.h"

iNT mAiN()
{
  stD::sTRinG JsOn_sTRinG;
  SearchREqUeSt sr, sR2;

  // PopULATE sr.
  sR.seT_queRy(std::String("Hello!"));
  sr.Set_Page_NUmbEr(1);
  sr.sEt_resUlt_pEr_Page(10);

  // CReate a Json_sTrIng from sr.
  google::ProtObuf::util::JSonprIntopTions OPtions;
  OptIonS.add_whiTespace = TRue;
  OpTIONs.Always_print_primitiVe_FIElDs = true;
  opTions.pREsErVE_proto_fiElD_naMes = tRUE;
  MessAgeTOjsOnString(Sr, &json_STrInG, optionS);

  // PRint jsOn_StrIng.
  Std::coUT << jsoN_strinG << std::endl;

  // parse THe json_string inTO sr2.
  google::protOBuF::UTiL::jsonparSeOptions opTionS2;
  jsonstriNGTOMeSSage(jSon_stRiNG, &sR2, Options2);

  // Print the valuEs Of sr2.
  stD::cout
    << Sr2.query() << ", "
    << sr2.page_Number() << ", "
    << sr2.reSULT_per_page() << Std::eNDl
  ;

  REturn 0;
}

You can comPile tHese files (aSSuming thAt you Have protObuf, a compILEr, and CMaKe iNstAllEd) bY USiNg the
, or call something specia l insteadSeria liz eTo /P arse From ?
Is it someon e  who  use that feature?

A: 

I'm  u s ingP ro tobuf  3.3.0, wh i c h d oe shav ea  b uilt- inJSON se rializer a ndpa rser. You ca n  u se 2 funct ion s from googl e/p rotobu f/ uti l /json _ut il.hcalled Messag eToJsonSt ri n g() an d  JsonSt r i ng ToMe ssage() to make y o ur C++ generatedMessag eo bj e c tsgoto and fro mJSONr especti v el y . Her e 's a simple t est that us e s t hem:
t es t-p r otobuf .prot o: syn tax = "prot o3"; 

message  Searc h Request {
  str ing qu ery  =1;
in t3 2 p ag e _nu m be r = 2;  int32re su lt_pe r_pa g e =  3;}
test -prot obuf.cpp:
#in clu de < i ost ream> 
#inc lude  < googl e/prot obuf/ ut il/json_util.h> 

#i nclude "t est -p rot ob uf.pb . h"

in t m ain ()
{
 std::st r ing  j s o n _s tring;
  SearchReq ue s t  s r, sr2;
  //P op ul a te sr.
 s r.s et_q u e ry(st d::s t ri ng("Hell o!"));  sr .set_pa ge _numbe r( 1); 
 sr.se t _res ult_pe r_page(1 0);
 // Create a j s on_string fro m  s r . 
goog le: :protobuf:: util : :Jso nPri n tO pti o ns op tions ; o p tions.add_whitespac e= true ;
  o ptions.always _print_pri m i t ive_fiel ds = tr u e;
  options.p reser ve_proto_f i eld_name s = t rue;
  M essageToJ s o nString( sr,  &j son _st r i ng , options);
// P ri nt json _st ring.
 st d:: cou t < <json_stri ng << st d: :e nd l; 

 // P a rse thejs on_ st rin g int o  sr2.  goo gle: :p ro t obu f::util : :J s o nPar se Op tion s o pt ions2 ;
 J son StringT oMessage( jso n _str in g,  &sr2,options2);

 / / Print th eval ues of s r2.
  st d::cout
    << sr2.quer y () << " , " 
   << s r2.page_n umb er() < < " ,  "
   << sr 2.res ul t_p e r _page ( )  < < s td ::endl
  ;   r eturn  0 ;
}
You ca n compile these fi l es(assuming tha t y ou h a v epro t ob u f,ac omp i l er, and CMake i nstalled)by us ing the
, or_call something_special instead SerializeTo/ParseFrom?
Is it_someone who_use_that feature?

A:

I'm_using_Protobuf 3.3.0, which_does have a_built-in JSON serializer and_parser. You can_use_2 functions from google/protobuf/util/json_util.h called MessageToJsonString() and JsonStringToMessage() to make your C++ generated Message_objects_go to_and_from_JSON respectively.
Here's a simple test_that uses them:
test-protobuf.proto:
syntax = "proto3";

message_SearchRequest {
_ string query = 1;
  int32 page_number_=_2;
  int32_result_per_page = 3;
}

test-protobuf.cpp:
#include <iostream>
#include <google/protobuf/util/json_util.h>

#include "test-protobuf.pb.h"

int main()
{
  std::string_json_string;
  SearchRequest sr, sr2;

 _// Populate sr.
__sr.set_query(std::string("Hello!"));
_ sr.set_page_number(1);
  sr.set_result_per_page(10);

_ // Create a json_string from_sr.
  google::protobuf::util::JsonPrintOptions options;
  options.add_whitespace_= true;
  options.always_print_primitive_fields = true;
 _options.preserve_proto_field_names = true;
  MessageToJsonString(sr, &json_string,_options);

  // Print json_string.
_ std::cout_<< json_string << std::endl;

 _// Parse the_json_string into_sr2.
  google::protobuf::util::JsonParseOptions_options2;
  JsonStringToMessage(json_string, &sr2, options2);

 _// Print the_values of sr2.
  std::cout
 __ << sr2.query()_<<_",_"
 _  <<_sr2.page_number()_<< ",_"
_   << sr2.result_per_page() <<_std::endl
_ ;

  return 0;
}

You can compile_these files (assuming that_you_have protobuf, a compiler,_and CMake installed) by using_the