google/protobuf.dart

Consider some extension member magic to avoid API noise in generated classes

kevmoo opened this issue · 4 comments

kevmoo commented

image

Could we move most of the instance members of GeneratedMessage to extensions?

They add SO MUCH NOISE to API docs – and just general auto-complete for end users.

As it stands, publishing a package of generated APIs using grpc.dart would be less than ideal.

CC @osa1 @mraleph

kevmoo commented

I'd also like to understand the need for:

  • info_
  • has* and clear*

Trying to understand how often these are really needed by humans using the generated API

We should probably just mark all of generated-code-private methods (prefixed with $_*) with @nodoc. We need to be careful with making them extensions - this can increase JS code size because static invocations are longer than method invocations.

has* and clear*

These are kinda part of a "canonical" protobuf API. Though I would expect generator to generate less "hazzers" for proto3 variant (as described here: https://github.com/protocolbuffers/protobuf/blob/main/docs/field_presence.md).

osa1 commented

These are already marked as @nodoc, we just need to publish a new version.

/// For generated code only.
/// @nodoc
T $_get<T>(int index, T defaultValue) =>
_fieldSet._$get<T>(index, defaultValue);
/// For generated code only.
/// @nodoc
T $_getN<T>(int index) => _fieldSet._$getND(index);
/// For generated code only.
/// @nodoc
T $_ensure<T>(int index) => _fieldSet._$ensure<T>(index);
/// For generated code only.
/// @nodoc
List<T> $_getList<T>(int index) => _fieldSet._$getList<T>(index);
/// For generated code only.
/// @nodoc
Map<K, V> $_getMap<K, V>(int index) => _fieldSet._$getMap<K, V>(this, index);
/// For generated code only.
/// @nodoc
bool $_getB(int index, bool defaultValue) =>
_fieldSet._$getB(index, defaultValue);
/// For generated code only.
/// @nodoc
bool $_getBF(int index) => _fieldSet._$getBF(index);
/// For generated code only.
/// @nodoc
int $_getI(int index, int defaultValue) =>
_fieldSet._$getI(index, defaultValue);
/// For generated code only.
/// @nodoc
int $_getIZ(int index) => _fieldSet._$getIZ(index);
/// For generated code only.
/// @nodoc
String $_getS(int index, String defaultValue) =>
_fieldSet._$getS(index, defaultValue);
/// For generated code only.
/// @nodoc
String $_getSZ(int index) => _fieldSet._$getSZ(index);
/// For generated code only.
/// @nodoc
Int64 $_getI64(int index) => _fieldSet._$getI64(index);
/// For generated code only.
/// @nodoc
bool $_has(int index) => _fieldSet._$has(index);
/// For generated code only.
/// @nodoc
void $_setBool(int index, bool value) => _fieldSet._$set(index, value);
/// For generated code only.
/// @nodoc
void $_setBytes(int index, List<int> value) => _fieldSet._$set(index, value);
/// For generated code only.
/// @nodoc
void $_setString(int index, String value) => _fieldSet._$set(index, value);