ProtobufEncode
ProtobufEncode
The ProtobufEncode block is an operator, that allows to encode input arguments as fields in Protocol Buffers message encoding.
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 |
---|---|---|
Protocol Buffers message field name to encode | Any number of user-configurable input arguments | Argument value will be encoded to output as Protocol Buffers message field |
Out | Predefined output argument | The Protocol Buffers encoded message (binary string) |
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 output encoding. There can be several messages described in the Proto definition, but only the one named in Message is used for this operator for encoding. |
Note: The encoded message (Out 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 encode a Protocol Buffers message like this:
syntax = "proto3"; message SensorInfo { string name = 1; uint64 timestamp = 2; double value = 3; }
The ProtobufEncode operator Proto attribute was set to the message definition given above and the Message attribute was set to SensorInfo. To get the message field values for encoding, 3 input arguments were added to the block: name (Sequencer.Argument<string>), timestamp ((Sequencer.Argument<uint64_t>) and value ((Sequencer.Argument<string>)). These arguments' current values (and as for all operators, the argument values can be routed from any value object in CDP) will be used to encode and output the Protocol Buffers message, as can be seen in the block diagram (with the sidebar, to show the argument and attribute values):
See also ProtobufEncoder, ProtobufDecode, 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.