greptimedb icon indicating copy to clipboard operation
greptimedb copied to clipboard

Consider whether the protobuf optional feature is required

Open evenyag opened this issue 3 years ago • 2 comments

The optional feature is only available in newer protoc releases, only the latest Linux distribution can install them via the package manager. This is a little bit inconvenient since some developers may use an old Linux distribution, or already have protoc installed in their environment. We need to consider whether current dependencies on the optional feature are necessary.

evenyag avatar Nov 14 '22 03:11 evenyag

from prost's documentation https://docs.rs/prost/latest/prost/#field-modifiers:

Note that in proto3 the default representation for all user-defined message types is Option<T>, and for scalar types just T (during decoding, a missing value is populated by T::default()). If you need a witness of the presence of a scalar type T, use the optional modifier to enforce an Option<T> representation in the generated Rust struct.

If I understand correct, We have to add this optional modifier to force an Option<T>'s default value to be None rather than Some(T::default()).

waynexia avatar Nov 14 '22 14:11 waynexia

from prost's documentation https://docs.rs/prost/latest/prost/#field-modifiers:

Note that in proto3 the default representation for all user-defined message types is Option, and for scalar types just T (during decoding, a missing value is populated by T::default()). If you need a witness of the presence of a scalar type T, use the optional modifier to enforce an Option representation in the generated Rust struct.

If I understand correct, We have to add this optional modifier to force an Option<T>'s default value to be None rather than Some(T::default()).

You are right. The initial intention was to distinguish "absent" from "empty" of string and bytes. There are indeed no strong motivations that we have to use optional. I will remove them.

MichaelScofield avatar Nov 19 '22 06:11 MichaelScofield

closed by #756

MichaelScofield avatar Dec 23 '22 04:12 MichaelScofield