PSA: Replacing RTCStatsMember<T> with absl::optional<T> in progress, use Attributes() instead of Members()

627 views
Skip to first unread message

Henrik Boström

unread,
Jan 12, 2024, 10:12:14 AM1/12/24
to discuss-webrtc
Hello,

In an effort to reduce the number of special purpose constructs in favor of more standard ones, RTCStatsMember<T> and its abstraction RTCStatsMemberInterface will be removed in favor of using absl::optional<T> to represent GetStats() statistics.

For those referring the C++ fields of the RTCStats objects directly, little will change but you should make sure to use `stat.has_value()` instead of `stat.is_defined()` to be compatible with the upcoming absl::optional<T> change.

For those iterating all stats members in a more abstract way, you need to migrate from RTCStats::Members() returning a list of const RTCStatsMemberInterface* to RTCStats::Attributes(), returning a list of Attributes. The Members() method will soon be deleted.

The Attribute can be used in a similar way as RTCStatsMemberInterface, e.g.
```
// for each attribute in rtc_stats.Attributes()...
if (!attribute.has_value())
  continue;
if (attribute.holds_alternative<std::string>()) {
  RTC_LOG(LS_INFO) << attribute.name() << " is a string with value: \"" << attribute.get<std::string>() << "\".";
}
```
For reference, here is an example of migrating from members to attributes.

Kostya Vasilyev

unread,
Jan 12, 2024, 12:32:24 PM1/12/24
to discuss...@googlegroups.com
Hello,

If the motivation is to use standard constructs, maybe consider std::optional instead of absl::optional?

— K

--
This list falls under the WebRTC Code of Conduct - https://webrtc.org/support/code-of-conduct.
---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/7094e943-9505-43f9-818c-820a3d77404bn%40googlegroups.com.

Philipp Hancke

unread,
Jan 13, 2024, 12:54:35 AM1/13/24
to discuss...@googlegroups.com
absl::optional is an alias for std::optional (for Chromium, 
but moving forward it might indeed make sense to just write it as such.

Given almost 5000 use of absl::optional I doubt anyone wants to do a search-replace, maybe after next Christmas ;-)

Henrik Boström

unread,
Jan 16, 2024, 3:08:40 AM1/16/24
to discuss-webrtc
For now, all of webrtc uses absl::optional rather than std::optional so we should be consistent. But I think you're right in that we can change from absl to std, I asked around and AFAIK there is nothing blocking that. But that's a separate effort.
Reply all
Reply to author
Forward
0 new messages