是否有用于检查协议缓冲区的确定的*nix命令行工具?

com*_*orm 39 unix command-line-interface protocol-buffers

我正在寻找一个命令行实用程序,它至少会以人类可读的形式呈现二进制protobuf数据.过滤和选择选项(沿着cut文本行)会很好,但主要目的是使数据可见以便进行调试.

如果没有该工作的权威工具,相关包的链接就可以了.

Ken*_*rda 43

协议编译器 - protoc具有通过--decode--decode_raw标志内置的此功能.这与用于从.proto文件生成代码的工具相同,因此可能已经安装.

例如:

protoc --decode_raw < message.bin
Run Code Online (Sandbox Code Playgroud)

或者使用.proto文件:

protoc --decode mypkg.MyType myschema.proto < message.bin
Run Code Online (Sandbox Code Playgroud)

这是--help文字:

Usage: protoc [OPTION] PROTO_FILES
Parse PROTO_FILES and generate output based on the options given:
  -IPATH, --proto_path=PATH   Specify the directory in which to search for
                              imports.  May be specified multiple times;
                              directories will be searched in order.  If not
                              given, the current working directory is used.
  --version                   Show version info and exit.
  -h, --help                  Show this text and exit.
  --encode=MESSAGE_TYPE       Read a text-format message of the given type
                              from standard input and write it in binary
                              to standard output.  The message type must
                              be defined in PROTO_FILES or their imports.
  --decode=MESSAGE_TYPE       Read a binary message of the given type from
                              standard input and write it in text format
                              to standard output.  The message type must
                              be defined in PROTO_FILES or their imports.
  --decode_raw                Read an arbitrary protocol message from
                              standard input and write the raw tag/value
                              pairs in text format to standard output.  No
                              PROTO_FILES should be given when using this
                              flag.
  -oFILE,                     Writes a FileDescriptorSet (a protocol buffer,
    --descriptor_set_out=FILE defined in descriptor.proto) containing all of
                              the input files to FILE.
  --include_imports           When using --descriptor_set_out, also include
                              all dependencies of the input files in the
                              set, so that the set is self-contained.
  --include_source_info       When using --descriptor_set_out, do not strip
                              SourceCodeInfo from the FileDescriptorProto.
                              This results in vastly larger descriptors that
                              include information about the original
                              location of each decl in the source file as
                              well as surrounding comments.
  --error_format=FORMAT       Set the format in which to print errors.
                              FORMAT may be 'gcc' (the default) or 'msvs'
                              (Microsoft Visual Studio format).
  --print_free_field_numbers  Print the free field numbers of the messages
                              defined in the given proto files. Groups share
                              the same field number space with the parent 
                              message. Extension ranges are counted as 
                              occupied fields numbers.
  --plugin=EXECUTABLE         Specifies a plugin executable to use.
                              Normally, protoc searches the PATH for
                              plugins, but you may specify additional
                              executables not in the path using this flag.
                              Additionally, EXECUTABLE may be of the form
                              NAME=PATH, in which case the given plugin name
                              is mapped to the given executable even if
                              the executable's own name differs.
  --cpp_out=OUT_DIR           Generate C++ header and source.
  --java_out=OUT_DIR          Generate Java source file.
  --python_out=OUT_DIR        Generate Python source file.
Run Code Online (Sandbox Code Playgroud)

  • 看来这是一种未记录的称为“文本格式”的东西 - 请参阅https://github.com/google/protobuf/issues/3755 (4认同)
  • 一直在我的鼻子底下.感谢您的写作,希望它也能帮助其他人. (2认同)
  • @BruceAdams如果您可以相信,格式实际上早于JSON.与JSON的不同之处包括您提到的引用以及重复字段由字面上具有多个字段实例(而不是方括号中的列表)表示的事实.与你的链接中的pherl所说的相反,跨语言*的TextFormat实现*旨在可以互操作,或者无论如何都是我的时间.以下是适用于它的C++ API:https://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.text_format (2认同)