You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/dev-sdk.md
+19-3Lines changed: 19 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -47,8 +47,10 @@ Any changes to the protocol must bump the version by one. On the _master_ branch
47
47
##### Enums
48
48
49
49
* Follow the [Google protobuf style for enums](https://developers.google.com/protocol-buffers/docs/style#enums)
50
-
* Enum of zero value should be labeled as `XXX_UNKNOWN`, `XXX_NONE`, or `XXX_UNDEFINED` to check if it was not set.
51
-
* Wrap enums in messages so that their string values are clearer. Example:
50
+
* According to the Google guide, the enum of zero value should be labeled as `UNSPECIFIED` to check if it was not set since `0` is the default value set when the client does not provide it.
51
+
* Wrap enums in messages so that their string values are clearer. Wrapping an enum in a message also has the benefit of not needing to prefix the enums with namespaced information. For example, instead of using the enum `XATTR_UNSPECIFIED`, the example above uses just `UNSPECIFIED` since it is inide the `Xattr` message. The generated code will be namepaced:
52
+
53
+
Proto:
52
54
53
55
```proto
54
56
// Xattr defines implementation specific volume attribute
@@ -62,7 +64,16 @@ message Xattr {
62
64
}
63
65
```
64
66
65
-
Wrapping an enum in a message also has the benefit of not needing to prefix the enums with namespaced information. For example, instead of using the enum `XATTR_UNSPECIFIED`, the example above uses just `UNSPECIFIED` since it is inide the `Xattr` message. The generated code will be namepaced:
67
+
Using the enum in a Proto
68
+
69
+
```proto
70
+
message VolumeSpec {
71
+
// Holds the extended attributes for the volume
72
+
Xattr.Value xattr = 1;
73
+
}
74
+
```
75
+
76
+
Notice the namepaced and string values in the generated output code:
66
77
67
78
```go
68
79
typeXattr_Valueint32
@@ -82,6 +93,11 @@ var Xattr_Value_value = map[string]int32{
0 commit comments