How can I set the values?
you can't when it is defined like you have shown. The message HTML
only contains a definition of an enum but no actual fields. You can either add a field in the message HTML
, or define the type in Page
as HTML.Type
instead of just HTML
:
test.proto:
message HTML{
enum Type {
NO_TYPE = 0;
HTML5 = 1;
XHTML = 2;
}
}
message Page{
optional HTML.Type _html = 1;
}
and then create a file test.txt:
_html: HTML5
you can create a binary file like this:
protoc --experimental_allow_proto3_optional --encode Page test.proto < test.txt > binary.data
and decode it :
protoc --experimental_allow_proto3_optional --decode Page test.proto < binary.data
The last command prints:
_html: HTML5
Apart from the enum definition, the HTML
message is an Empty
message, which even exists as a predefined message:
// A generic empty message that you can re-use to avoid defining duplicated
// empty messages in your APIs. A typical example is to use it as the request
// or the response type of an API method.
// The JSON representation for Empty
is empty JSON object {}
.
message Empty {}