ProtobufDecode
ProtobufDecode
The ProtobufDecode block is an operator, that allows to decode input binary string from Protocol Buffers message encoding to output arguments.
Protocol Buffers (protobuf) is a method for serializing structured data, developed by Google. It is designed to be a language-agnostic, platform-neutral, and extensible mechanism for serializing structured data. Protocol Buffers is widely used for communication protocols, data storage, and configuration files, among other things.
Protocol Buffers uses an Interface Definition Language (IDL) to define data structures - message types and their fields. Protocol Buffers definitions are usually contained in the files having .proto extension and have to be compiled to the programming language used by the application using protoc compiler. For this block you only need to copy the definitions into the block Proto attribute value instead and the definitions will be runtime-compiled from there.
Arguments
Name | Appearance | Description |
---|---|---|
In | Predefined input argument | The Protocol Buffers encoded message (binary string) |
Protocol Buffers message field name to decode | Any number of user-configurable output arguments | Argument name will be searched from the Protocol Buffers message field list and when found, the this argument value will be set to the field value. When the field named as the argument is not found, then the argument value will be set to empty (or 0 for numeric arguments). |
Properties
Name | Description |
---|---|
Proto | Protocol Buffers message definition in Interface Definition Language (IDL). It can be copied here from the .proto file, used for the particular communication definition. |
Message | Message name to use from the Protocol Buffers definition for the decoding. There can be several messages described in the Proto definition, but only the one named in Message is used for this operator for decoding. |
Note: The message (In argument) may contain non-printable characters that are not always printable in the CDP Studio Block Diagram next to the connection line. But you can still get some printed representation of the message binary body from the Table Editor or in the Block Diagram sidebar.
Example
The following block diagram shows how to decode a Protocol Buffers message like this:
syntax = "proto3"; message SensorInfo { string name = 1; uint64 timestamp = 2; double value = 3; }
The ProtobufDecode operator Proto attribute was set to the message definition given above and the Message attribute was set to SensorInfo. To decode message fields, 3 output arguments were added to the block: name (Sequencer.Argument<string>), timestamp ((Sequencer.Argument<uint64_t>) and value ((Sequencer.Argument<string>)). These fields are looked up from the input Protocol Buffers message and when found, their values will be set to the field values, as can be seen in the block diagram:
See also ProtobufDecoder, ProtobufEncode, and Argument.
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.