You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For each protobuf class there is a default instance, which should be read-only. Mixins may add extra fields and a way to set them. Any mixin with a setter should throw an exception if the instance is read-only.
Currently the _isReadOnly getter is private. We should make it public. In the meantime, a mixin can implement the check like this:
if (this is ReadonlyMessageMixin) {
throw new UnsupportedError(
"attempted to set <somefield> on a read-only message (${info_.messageName})");
}
The text was updated successfully, but these errors were encountered:
At the time I added mixins, there were only a few, either in the open source code or in the google3 version. If all the mixins handle readonly protobufs correctly then there is no issue. It might be good to update them to call isFrozen?
I think this bug was to document the workaround and to warn about what might go wrong if the ability to add mixins was used more widely. (For example, users started writing their own mixins.)
It probably could be closed. If someone were to write a guide to implementing protobuf mixins then it should have a reminder to handle the frozen case correctly, but it doesn't seem too likely?
For each protobuf class there is a default instance, which should be read-only. Mixins may add extra fields and a way to set them. Any mixin with a setter should throw an exception if the instance is read-only.
Currently the _isReadOnly getter is private. We should make it public. In the meantime, a mixin can implement the check like this:
The text was updated successfully, but these errors were encountered: