Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More GeneratedMessage docs, hide meta library #882

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions protobuf/lib/meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/// Provides metadata about GeneratedMessage and ProtobufEnum to
/// dart-protoc-plugin. (Experimental API; subject to change.)
/// @nodoc
library protobuf.meta;

// ignore_for_file: constant_identifier_names
Expand Down
4 changes: 2 additions & 2 deletions protobuf/lib/src/protobuf/field_set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ class _FieldSet {
String get _messageName => _meta.qualifiedMessageName;
bool get _hasRequiredFields => _meta.hasRequiredFields;

/// The FieldInfo for each non-extension field.
/// The [FieldInfo] for each non-extension field.
Iterable<FieldInfo> get _infos => _meta.fieldInfo.values;

/// The FieldInfo for each non-extension field in tag order.
/// The [FieldInfo] for each non-extension field in tag order.
Iterable<FieldInfo> get _infosSortedByTag => _meta.sortedByTag;

_ExtensionFieldSet _ensureExtensions() =>
Expand Down
12 changes: 10 additions & 2 deletions protobuf/lib/src/protobuf/generated_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ abstract class GeneratedMessage {
@override
int get hashCode => _fieldSet._hashCode;

/// Returns a String representation of this message.
/// Returns a [String] representation of this message.
///
/// This representation is similar to, but not quite, the Protocol Buffer
/// TextFormat. Each field is printed on its own line. Sub-messages are
Expand All @@ -143,7 +143,7 @@ abstract class GeneratedMessage {
@override
String toString() => toDebugString();

/// Returns a String representation of this message.
/// Returns a [String] representation of this message.
///
/// This generates the same output as [toString], but can be used by mixins
/// to compose debug strings with additional information.
Expand All @@ -153,6 +153,11 @@ abstract class GeneratedMessage {
return out.toString();
}

/// Throws a [StateError] if the message has required fields without a value.
///
/// This library does not check in any of the methods that required fields in
/// have values. Use this method if you need to check that required fields
/// have values.
void check() {
if (!isInitialized()) {
final invalidFields = <String>[];
Expand All @@ -162,15 +167,18 @@ abstract class GeneratedMessage {
}
}

/// Serialize the message as the protobuf binary format.
Uint8List writeToBuffer() {
final out = CodedBufferWriter();
writeToCodedBufferWriter(out);
return out.toBuffer();
}

/// Same as [writeToBuffer], but serializes to the given [CodedBufferWriter].
void writeToCodedBufferWriter(CodedBufferWriter output) =>
_writeToCodedBufferWriter(_fieldSet, output);

/// Same as [mergeFromBuffer], but takes a [CodedBufferReader] input.
void mergeFromCodedBufferReader(CodedBufferReader input,
[ExtensionRegistry extensionRegistry = ExtensionRegistry.EMPTY]) {
final meta = _fieldSet._meta;
Expand Down