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
It is cumbersome and expensive ( getAllFields() in many cases would recreate the fields' map!).
However, to implement it from within the MessageOrBuilder, all needed is to just call internal map.isEmpty() or such.
There are so many valid and common cases for emptiness check, the are done often and in many places, so this API and performance optimization is crucial, IMHO.
There are two implementation alternatives:
with minimal/zero impact on compatibility - implement isEmpty() on basic classes AbstractMessage, DynamicMessage, and GeneratedMessage and their Builders.
more complete and consistent API, but could be impact on pure Message/Builder implementations, is implement option 1 plus add isEmpty() to (Lite)MessageOrBuilder interface.
Any implementation alternative will also solve the "is MessageOrBuilder default?" question, which currently resolved differently for GeneratedMessage and DynamicMessage.
The alternative 1 will require casting to these basic classes, so it is not w/o cons.
This request is not extremely urgent, so it could be implemented anytime after 2.6.1.
The text was updated successfully, but these errors were encountered:
Besides the approach you mentioned, you can also check whether a message is empty by "message.getSerializedSize() == 0". It's recommended and works for lite runtime as well.
Regarding the default instance of DynamicMessage, I think DynamicMessage.getDefaultInstance() not returning a singleton is a bug.
message.getSerializedSize() is expensive for non-empty messages; and it is awkward as well.
In order for DynamicMessage to have a singleton defaultInstance that can be compared with == you'll have to maintain internal thread-safe static Map<Descriptor, DynamicMessage> cache of defaults, which is relatively expensive.
In all cases, the most universal, easy to implement, and easiest and most conventional to use is isEmpty(); or if to go a bit further, size() in terms of the total number of fields. It is as conventional, as the Collection API, well understood and widely used.
At present, to find whether the MessageOrBuilder is empty one needs to call the following:
It is cumbersome and expensive ( getAllFields() in many cases would recreate the fields' map!).
However, to implement it from within the MessageOrBuilder, all needed is to just call internal map.isEmpty() or such.
There are so many valid and common cases for emptiness check, the are done often and in many places, so this API and performance optimization is crucial, IMHO.
There are two implementation alternatives:
Any implementation alternative will also solve the "is MessageOrBuilder default?" question, which currently resolved differently for GeneratedMessage and DynamicMessage.
The alternative 1 will require casting to these basic classes, so it is not w/o cons.
This request is not extremely urgent, so it could be implemented anytime after 2.6.1.
The text was updated successfully, but these errors were encountered: