envoyproxy / envoyproxy/nighthawk

adopt proto3 `optional` - explicit field presence

Open
#964 0 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
414
Forks
95
Avg merge
2d 9h
Merged PRs (30d)
11

Description

proto3 has restored `optional`, so for a field

```
syntax = "proto3";
message X {
optional bool mybool = 1;
}
```

we regain the ability to distinguish between
- primitive field unset (`has_mybool()` false)
- primitive field explicitly set to default value (`has_mybool()` true, `mybool()` false)

as in proto2.

`optional` is optional. If a field is marked `optional` in proto3, we get the proto2 behavior.

See https://developers.google.com/protocol-buffers/docs/proto3#specifying_field_rules.

We should consider adopting `optional`, moving away from wrappers like `google.protobuf.UInt32Value`.

If we created a clean proto, it could just be like:
```
syntax = "proto3";
message BenchmarkSpec {
optional uint32 requests_per_second = 1 [(validate.rules).uint32 = {gte: 1, lte: 1000000}];
optional uint32 connections = 2 [(validate.rules).uint32 = {gte: 1, lte: 1000000}];
// ...
```

The gRPC service would be surprisingly easy to update. Maybe:
```
message StartRequest {
oneof opts {
CommandLineOptions options = 1;
BenchmarkSpec benchmark_spec = 2;
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.