From b2b239b4760edd5a0768d9c6feb653eda1019266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Thu, 12 Oct 2023 17:30:38 +0200 Subject: [PATCH] More GeneratedMessage docs, hide meta library (#882) --- protobuf/lib/meta.dart | 1 + protobuf/lib/src/protobuf/field_set.dart | 4 ++-- protobuf/lib/src/protobuf/generated_message.dart | 12 ++++++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/protobuf/lib/meta.dart b/protobuf/lib/meta.dart index 2b249d18d..7f432638e 100644 --- a/protobuf/lib/meta.dart +++ b/protobuf/lib/meta.dart @@ -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 diff --git a/protobuf/lib/src/protobuf/field_set.dart b/protobuf/lib/src/protobuf/field_set.dart index fe5b7e042..0c8b064fa 100644 --- a/protobuf/lib/src/protobuf/field_set.dart +++ b/protobuf/lib/src/protobuf/field_set.dart @@ -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 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 get _infosSortedByTag => _meta.sortedByTag; _ExtensionFieldSet _ensureExtensions() => diff --git a/protobuf/lib/src/protobuf/generated_message.dart b/protobuf/lib/src/protobuf/generated_message.dart index 6239e0ec5..b6c352710 100644 --- a/protobuf/lib/src/protobuf/generated_message.dart +++ b/protobuf/lib/src/protobuf/generated_message.dart @@ -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 @@ -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. @@ -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 = []; @@ -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;