Skip to content

Commit

Permalink
More GeneratedMessage docs, hide meta library (#882)
Browse files Browse the repository at this point in the history
  • Loading branch information
osa1 authored Oct 12, 2023
1 parent 96d9522 commit b2b239b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
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 @@ -91,10 +91,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 @@ -137,7 +137,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 @@ -148,7 +148,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 @@ -158,6 +158,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 @@ -167,15 +172,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

0 comments on commit b2b239b

Please sign in to comment.