Closed 124C41p closed 1 year ago
I think the take_field_by
methods definitely make sense,
The iteration APIs feel sensible as well, what do you think of these signatures?
/// Iterator over all fields for which `has_field` is true.
fn fields(&self) -> impl Iterator<Item = (FieldDescriptor, &'_ Value>);
/// Iterator over all extensions for which `has_extension` is true.
fn extensions(&self) -> impl Iterator<Item = (ExtensionDescriptor, &'_ Value>);
In future, there could be a variant of fields
which includes proto3 fields set to their default value (useful for implementing the JSON serialization with skip_default_fields set to false, for example). However I don't think that one is any more efficient than an implementation using existing APIs.
I've implemented the new APIs in #55
Looks really good to me! Do you mind also adding those destructive iterators?
fn take_fields(&mut self) -> impl Iterator<Item = (FieldDescriptor, Value>)>;
fn take_extensions(&mut self) -> impl Iterator<Item = (ExtensionDescriptor, Value>)>;
(for completeness you would probably also want to add fields_mut
and extensions_mut
in this case)
Thanks a lot!
I've added the extra methods to #52, if you think they look good I'll publish a new version tomorrow
There are two categories of public functions on
DynamicMessage
for accessing their field values:get_field_by_*
andget_field_by_*_mut
. However, I am missing functions for deconstructing a Message, i.e. for taking ownership of a field value and setting the field toNone
(likeOption::take
). Do you mind adding functionstake_field_by_*(&mut self, ...) -> Option<Value>
?I am also missing iterators for the fields of a
DynamicMessage
(.iter()
,.iter_mut()
,.into_iter()
). At the moment, I am doing the following for iterating over all known fields of a message which have been set:This however is certainly not as efficient as it could be.