Protobuf
Encode and decode Protocol Buffers messages from the text of a .proto file, without generated classes, and inspect unknown messages. Typical uses: talk to services or devices that use Protobuf messages.
protobuf encodeprotobuf encodeprotobuf decodeprotobuf decodeprotobuf decode_rawprotobuf decode_raw

protobuf encode <proto> <message> <json_value>


Description

    Encode a JSON object to the wire format, as base64

Parameters

    proto:   The text of a .proto file, or the path of one (same rights as file load) - String - required
    message:   The message: its full name (pkg.Outer.Inner), or a short name if it is unique - String - required
    json_value:   The message, as a JSON object - String - required
admin
protobuf encode "syntax = \"proto3\"; message Test1 { int32 a = 1; string b = 2; }" "Test1" "{\"a\": 150}"
mentdb
CJYB
With a list, an enum, a map and a oneof
admin
protobuf encode "syntax = \"proto3\"; message Measure { string sensor = 1; double value = 2; int64 at = 3; repeated int32 flags = 4; enum Unit { C = 0; F = 1; } Unit unit = 5; map<string, string> tags = 6; oneof source { string host = 7; int32 line = 8; } Measure previous = 9; }" "Measure" "{\"sensor\": \"T1\", \"value\": 21.5, \"at\": 1793850000, \"flags\": [1, 2, 300], \"unit\": \"F\", \"tags\": {\"room\": \"12\"}, \"host\": \"plc1\"}"
mentdb
CgJUMREAAAAAAIA1QBiQ9a/XBiIEAQKsAigBMgoKBHJvb20SAjEyOgRwbGMx
Two members of a oneof are refused
admin
protobuf encode "syntax = \"proto3\"; message Measure { string sensor = 1; double value = 2; int64 at = 3; repeated int32 flags = 4; enum Unit { C = 0; F = 1; } Unit unit = 5; map<string, string> tags = 6; oneof source { string host = 7; int32 line = 8; } Measure previous = 9; }" "Measure" "{\"host\": \"a\", \"line\": 1}"
mentdb
ERROR: Sorry, an error appears (the fields 'host' and 'line' are in the same oneof: give only one).
A required field of proto2 is missing
admin
protobuf encode "syntax = \"proto2\"; message Item { required int32 id = 1; optional string name = 2 [default = \"none\"]; repeated int32 v = 3; }" "Item" "{\"name\": \"x\"}"
mentdb
ERROR: Sorry, an error appears (the required field 'id' is missing).

protobuf encode <proto> <message> <json_value> <json_params>


Description

    Encode with parameters: output (base64 or hex), out_path (writes a binary file; result {file, bytes}), overwrite (false), import_dir, max_depth, max_items

Parameters

    proto:   The text of a .proto file, or the path of one (same rights as file load) - String - required
    message:   The message: its full name (pkg.Outer.Inner), or a short name if it is unique - String - required
    json_value:   The message - String - required
    json_params:   The parameters - String - required
admin
protobuf encode "syntax = \"proto3\"; message Test1 { int32 a = 1; string b = 2; }" "Test1" "{\"a\": 150, \"b\": \"testing\"}" "{\"output\": \"hex\"}"
mentdb
089601120774657374696e67
To a file
admin
protobuf encode "syntax = \"proto3\"; message Test1 { int32 a = 1; string b = 2; }" "Test1" "{\"a\": 150}" "{\"out_path\": \"tmp/doc_test1.bin\", \"overwrite\": true}"
mentdb
{"file": "tmp/doc_test1.bin", "bytes": 3}
Used in use cases (1 recipe)

    Integrator & ETL developer › Build and read a Protocol Buffers message of a sensor, from the text of its .proto
Often used with

    protobuf decode  ·  protobuf decode_raw

protobuf decode <proto> <message> <payload>


Description

    Decode a base64 payload to a JSON object, with the fields present only

Parameters

    proto:   The text of a .proto file, or the path of one (same rights as file load) - String - required
    message:   The message: its full name (pkg.Outer.Inner), or a short name if it is unique - String - required
    payload:   The message in base64 - String - required
admin
protobuf decode "syntax = \"proto3\"; message Test1 { int32 a = 1; string b = 2; }" "Test1" "CJYB"
mentdb
{"a": 150}
A damaged payload
admin
protobuf decode "syntax = \"proto3\"; message Test1 { int32 a = 1; string b = 2; }" "Test1" "CJ"
mentdb
ERROR: Sorry, an error appears (the protobuf data is truncated (varint)).

protobuf decode <proto> <message> <payload> <json_params>


Description

    Decode with parameters: encoding (base64, hex, or file: payload is then a path), defaults (false; true adds the absent fields with their default value: zero, empty, the proto2 default, null for a message or an optional without default; the members of a oneof stay absent), partial (false; true accepts a missing required field), import_dir, max_bytes, max_depth, max_items

Parameters

    proto:   The text of a .proto file, or the path of one (same rights as file load) - String - required
    message:   The message: its full name (pkg.Outer.Inner), or a short name if it is unique - String - required
    payload:   The message - String - required
    json_params:   The parameters - String - required
admin
protobuf decode "syntax = \"proto3\"; message Test1 { int32 a = 1; string b = 2; }" "Test1" "089601180a" "{\"encoding\": \"hex\"}"
mentdb
{"a": 150, "_unknown": [{"field": 3, "wire_type": 0, "base64": "Cg=="}]}
With the defaults of proto2
admin
protobuf decode "syntax = \"proto2\"; message Item { required int32 id = 1; optional string name = 2 [default = \"none\"]; repeated int32 v = 3; }" "Item" "0807" "{\"encoding\": \"hex\", \"defaults\": true}"
mentdb
{"id": 7, "name": "none", "v": []}
Used in use cases (1 recipe)

    Integrator & ETL developer › Build and read a Protocol Buffers message of a sensor, from the text of its .proto
Often used with

    protobuf decode_raw  ·  protobuf encode

protobuf decode_raw <payload>


Description

    Show the structure of a base64 message without any .proto: JSON array of {field, wire, ...}. varint: value, zigzag; fixed64: value, as_double; fixed32: value, as_float; len: kind (string, message, bytes) and value; group: value. The meaning is a guess: only the numbers are certain

Parameters

    payload:   The message in base64 - String - required
admin
protobuf decode_raw "CJYBEgd0ZXN0aW5n"
mentdb
[{"field": 1, "wire": "varint", "value": 150, "zigzag": 75}, {"field": 2, "wire": "len", "kind": "string", "value": "testing"}]

protobuf decode_raw <payload> <json_params>


Description

    Show the structure with parameters: encoding (base64, hex or file), max_bytes, max_depth, max_items

Parameters

    payload:   The message - String - required
    json_params:   The parameters - String - required
admin
protobuf decode_raw "1a03089601" "{\"encoding\": \"hex\"}"
mentdb
[{"field": 3, "wire": "len", "kind": "message", "value": [{"field": 1, "wire": "varint", "value": 150, "zigzag": 75}]}]
Used in use cases (1 recipe)

    Integrator & ETL developer › Build and read a Protocol Buffers message of a sensor, from the text of its .proto
Often used with

    protobuf decode  ·  protobuf encode