2016-01-22 20 views
17

Sto cercando un'utilità della riga di comando che, come minimo, renderà i dati protobuf binari in formato leggibile. Le opzioni di filtro e selezione (lungo le linee di cut per il testo) sarebbero buone, ma l'oggetto principale è rendere i dati visibili a scopo di debug.Esiste uno strumento da riga di comando definitivo * nix per l'ispezione dei buffer di protocollo?

Se non esiste uno strumento definitivo per il lavoro, i collegamenti ai pacchetti pertinenti vanno bene.

+1

Dai un'occhiata alla comandi ProtoC integrato nel buffer di protocollo , ha opzioni per decodificare (--decode) un messaggio binario in testo (e riconvertirlo tramite il --encode opzione; probabilmente non funzionerà con i messaggi delimitati da java. Ci sono programmi di utilità per convertire pb in Xml/JSon. Se si utilizza <= 2.6.1, esiste https://sourceforge.net/projects/protobufeditor/ –

+0

Grazie, darò un'occhiata. – comingstorm

+0

Tale strumento potrebbe [convertire i buffer del protocollo in JSON] (https://stackoverflow.com/questions/2544580/is-there-a-standard-mapping-between-json-and-protocol-buffers). – Raedwald

risposta

21

Il compilatore di protocollo - protoc - ha questa funzionalità integrata tramite i flag --decode e --decode_raw. Questo è lo stesso strumento che usi per generare il codice da un file .proto quindi probabilmente è già installato.

Ad esempio:

protoc --decode_raw < message.bin 

oppure utilizzando il file .proto:

protoc --decode mypkg.MyType myschema.proto < message.bin 

Ecco il testo --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. 
+2

Proprio sotto il mio naso tutto il tempo. Grazie per l'articolo, speriamo che possa aiutare anche gli altri. – comingstorm

+0

Esistono soluzioni alternative per utilizzare la CLI/lo strumento per analizzare i messaggi delimitati (Java), per caso? –

+0

@decimusphostle Sfortunatamente, io non la penso così. Il supporto per i messaggi delimitati solo recentemente è arrivato nella libreria C++ dopo un lungo periodo di trascinamento dei piedi da parte dei manutentori. Presumibilmente qualcuno dovrà inviare loro un PR per aggiungere il supporto della riga di comando. –