Checking if [Size] returns 0 is an easy way to recognize empty messages:
()
| 15 | |
| 16 | // Checking if [Size] returns 0 is an easy way to recognize empty messages: |
| 17 | func ExampleSize() { |
| 18 | var m proto.Message |
| 19 | if proto.Size(m) == 0 { |
| 20 | // No fields set (or, in proto3, all fields matching the default); |
| 21 | // skip processing this message, or return an error, or similar. |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | func TestSizeAnyNonNilButEmpty(t *testing.T) { |
| 26 | ne := &anypb.Any{ |