0
0
IOT Protocolsdevops~20 mins

Protocol Buffers (protobuf) in IOT Protocols - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Protobuf Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of the protobuf compiler command?
You run the command protoc --python_out=. sensor.proto in your terminal. What is the expected result?
AGenerates a Python file named <code>sensor_pb2.py</code> in the current directory.
BGenerates a binary executable named <code>sensor</code> in the current directory.
COutputs the compiled protobuf schema as JSON to the terminal.
DThrows an error because <code>--python_out</code> is not a valid option.
Attempts:
2 left
💡 Hint
Think about what the --python_out flag does in the protoc command.
🧠 Conceptual
intermediate
2:00remaining
What does the 'optional' keyword mean in a protobuf message?
In a protobuf message definition, what does marking a field as optional imply?
AThe field must always be set; otherwise, the message is invalid.
BThe field is deprecated and should not be used anymore.
CThe field may or may not be set; if not set, it uses a default value.
DThe field is repeated multiple times in the message.
Attempts:
2 left
💡 Hint
Think about what 'optional' means in everyday choices.
Configuration
advanced
2:00remaining
How to define a repeated field in a protobuf message?
You want to define a protobuf message that holds multiple sensor readings in a list. Which of the following message definitions correctly uses a repeated field?
Amessage SensorData { repeated int32 readings = 1; }
Bmessage SensorData { optional int32 readings = 1; }
Cmessage SensorData { int32[] readings = 1; }
Dmessage SensorData { map<int32, int32> readings = 1; }
Attempts:
2 left
💡 Hint
Think about how to say 'many' in protobuf syntax.
Troubleshoot
advanced
2:00remaining
Why does this protobuf message cause a compilation error?
Given this protobuf message definition:
message Device {
  int32 id = 1;
  string name = 1;
}

Why does compiling this cause an error?
IOT Protocols
message Device {
  int32 id = 1;
  string name = 1;
}
AThe 'string' type is not supported in protobuf.
BField names cannot be 'id' or 'name' in protobuf messages.
CThe message must have at least three fields to compile.
DField numbers must be unique; both fields use number 1 causing a conflict.
Attempts:
2 left
💡 Hint
Check the numbers after the equals sign for each field.
Best Practice
expert
3:00remaining
Which practice helps maintain backward compatibility in protobuf schemas?
You want to update a protobuf message without breaking existing clients. Which practice below best supports backward compatibility?
AChange the type of existing fields to the new desired type directly.
BAdd new fields with new unique numbers and mark old fields as deprecated instead of removing them.
CReuse field numbers for new fields after removing old ones.
DRemove old fields and renumber all fields to keep numbers sequential.
Attempts:
2 left
💡 Hint
Think about how to keep old data working while adding new features.