Working with Proto files
Guidelines to follow when writing Protobuf code
Introduction
Creating files
syntax = "proto3"; // <-- This line is required for every file
import "x.proto"; // Must be in the same directory
import "google/protobuf/timestamp.proto"; // built-in Protobuf types
/// An enum allows you to define a closed set of values for a type.
///
/// The convention for enum members is SCREAMING_CASE.
enum Color {
COLOR_UNDEFINED = 0; // <-- see the below for details
RED = 1;
GREEN = 2;
BLUE = 3;
}
/// A message is like a class or struct, and may contain fields:
/// - All fields must have a unique ID, which may be any number
/// - All fields must have a type, (including types we defined)
/// - Nested messages are valid protobuf, but do not use them
/// - For a list, use `repeated`
///
/// The convention for field names is snake_case
message Pallate {
string name = 1;
repeated Color paints = 2;
int32 paint_count = 3; // int32 is the standard integer type
}Guidelines
More Resources
Last updated