What does the protobuf text format look like?

前端 未结 3 1491
南方客
南方客 2020-11-29 19:29

Google Protocol Buffers can not only be serialized in binary format, also be serialized as text. However I can\'t easily find examples of such text; what would it look like?

3条回答
  •  佛祖请我去吃肉
    2020-11-29 20:14

    Simplified, output from protoc.exe version 3.0.0 on window7 + cygwin

    Demo message

    $ cat demo.proto
       syntax = "proto3";  package demo;  message demo { repeated int32 n=1; } 
    

    Create a protobuf binary data

    $ echo n : [1,2,3]  | protoc --encode=demo.demo demo.proto > demo.bin
    

    Dumping proto data as text

     $ protoc --decode=demo.demo demo.proto < demo.bin
        n: 1
        n: 2
        n: 3
    

    And dump even if you don't have the proto definiton

        $ protoc --decode_raw < demo.bin  
        1: "\001\002\003" 
    

提交回复
热议问题