pub struct EpgStore { /* private fields */ }Expand description
A store for EIT data, providing high-level access to program events.
Wraps a crate::collect::EitCollector and maintains a deduplicated,
event list per service. Optionally accepts SDT data to attach service names.
Serde export serializes the cache as a map of ServiceKey → service data.
§Limitations
Events are deduplicated by (start_time, event_id) and never evicted
once stored: events removed from a re-versioned schedule, or events
already in the past, remain in the store. Call clear()
or retain_services() to bound long-running
memory.
§Example
use dvb_si::epg::{EpgStore, ServiceKey};
use chrono::Utc;
let mut store = EpgStore::new();
// store.feed(&eit_section_bytes).unwrap();
let key = ServiceKey {
original_network_id: 1,
transport_stream_id: 1,
service_id: 100,
};
let (now_evt, _next) = store.now_and_next(key, Utc::now());
if let Some(e) = now_evt {
println!("Now playing: {:?}", e.event_name);
}Implementations§
Source§impl EpgStore
impl EpgStore
Sourcepub fn feed(&mut self, bytes: &[u8]) -> CollectResult<()>
pub fn feed(&mut self, bytes: &[u8]) -> CollectResult<()>
Feed one EIT section into the store.
If a table becomes complete, its events are merged into the cache
(deduplicated by event_id, later insertions overwrite).
§Errors
Returns a crate::collect::CollectError if the section is malformed.
Sourcepub fn feed_with_pid(
&mut self,
pid: Option<u16>,
bytes: &[u8],
) -> CollectResult<()>
pub fn feed_with_pid( &mut self, pid: Option<u16>, bytes: &[u8], ) -> CollectResult<()>
Feed one EIT section with PID context into the store.
Sourcepub fn feed_sdt(&mut self, sdt: &CompleteSdt<'_>)
pub fn feed_sdt(&mut self, sdt: &CompleteSdt<'_>)
Feed completed SDT data to attach service names.
Accepts a parsed crate::collect::CompleteSdt from a
crate::collect::SectionSetCollector.
Sourcepub fn now_and_next(
&self,
key: ServiceKey,
at: DateTime<Utc>,
) -> (Option<&EpgEvent>, Option<&EpgEvent>)
pub fn now_and_next( &self, key: ServiceKey, at: DateTime<Utc>, ) -> (Option<&EpgEvent>, Option<&EpgEvent>)
Get the “now” and “next” events for a service.
Searches the event list for the given service and returns the event
currently on-air (“now”) and the next upcoming event (“next”) based
on reference time at.
“now” is the event where at falls within [start, start + duration).
“next” is the earliest event where start > at.
An event ending exactly at at is NOT considered “now” (exclusive end).
Returns (None, None) when the service is unknown or no event matches.
Sourcepub fn schedule(
&self,
key: ServiceKey,
from: DateTime<Utc>,
to: DateTime<Utc>,
) -> Option<Vec<&EpgEvent>>
pub fn schedule( &self, key: ServiceKey, from: DateTime<Utc>, to: DateTime<Utc>, ) -> Option<Vec<&EpgEvent>>
Query events with start times in the half-open range [from, to).
Returns events sorted by start time (valid times first, then by event_id). Events without a decodable start time are excluded.
Sourcepub fn service_name(&self, key: ServiceKey) -> Option<&str>
pub fn service_name(&self, key: ServiceKey) -> Option<&str>
Return the service name for a given key, if SDT data was fed.
Sourcepub fn services(&self) -> impl Iterator<Item = ServiceKey> + '_
pub fn services(&self) -> impl Iterator<Item = ServiceKey> + '_
Iterate the ServiceKeys of every service with cached EIT data, so
callers can walk the whole EPG (e.g. render a grid) without knowing the
service ids in advance. Order is unspecified.
Sourcepub fn events(&self, key: ServiceKey) -> Option<Vec<&EpgEvent>>
pub fn events(&self, key: ServiceKey) -> Option<Vec<&EpgEvent>>
Return all events for a service, sorted by start time (events without a valid start time sort last, then by event_id).
Sourcepub fn service_count(&self) -> usize
pub fn service_count(&self) -> usize
Return the number of services with cached EIT data.
Sourcepub fn event_count(&self) -> usize
pub fn event_count(&self) -> usize
Return the total number of events across all services.
Sourcepub fn retain_services<F>(&mut self, keep: F)
pub fn retain_services<F>(&mut self, keep: F)
Retain only services matching the given predicate.
Both the event cache and the underlying collector partial state for rejected keys are removed.