Skip to content

How to tell if a discovered topic is for a reader or writer #296

@samcarey

Description

@samcarey

I'm trying to figure out how to tell if a discovered topic is a reader or a writer.

Looking at the implementation of the discovered_topics in all_user_topics , it seems that there is a DiscoveredVia enum that could potentially be used to filter the topics based on DiscoveredVia::Publication or DiscoveredVia::Subscription like so:

pub fn discovered_writers(&self) -> impl Iterator<Item = &DiscoveredTopicData> {
    self
      .topics
      .iter()
      .filter(|(s, _)| !s.starts_with("DCPS"))
      .flat_map(move |(_, gm)| {
        gm.iter()
          .filter(|(_, (discovered_via, _))| discovered_via == &DiscoveredVia::Publication)
          .map(|(_, dtd)| &dtd.1)
      })
  }

The problem with this approach is that in , the DiscoveredVia value is overwritten with DiscoveredVia::Topic after a few seconds when more info on the topic is found here.

So, unless there's already a way to permanently distinguish readers from writers, I would propose that instead of overwriting the previous value with "DiscoveredVia::Topic", the original value be preserved somehow and used to filter with something like the function above. I might just patch in some extra variants (e.g. TopicPreviouslyPublication) temporarily for my immediate purposes. I'm still not sure if this would work if somehow the original DiscoveredVia::Publication was never set in the first place, if that's even possible. If you think that would be the best approach, I can open a PR.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions