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.
§Memory bounds
The store is bounded by two configurable caps (see module docs for
rationale and default values). Use with_max_services
and with_max_events_per_service to
tune them.
§Limitations
Events are deduplicated by event_id and stored within the configured
per-service cap. Events removed from a re-versioned schedule, or events
already in the past, remain in the store until evicted by
retain_services() or clear().
§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 new() -> Self
pub fn new() -> Self
Create a new, empty EPG store with default caps
(DEFAULT_MAX_SERVICES, DEFAULT_MAX_EVENTS_PER_SERVICE).
Sourcepub fn with_max_services(self, max_services: usize) -> Self
pub fn with_max_services(self, max_services: usize) -> Self
Replace the service-count cap (default DEFAULT_MAX_SERVICES).
When the cap is reached, events for new services are skipped until
retain_services or clear
frees capacity.
Sourcepub fn with_max_events_per_service(self, max_events_per_service: usize) -> Self
pub fn with_max_events_per_service(self, max_events_per_service: usize) -> Self
Replace the per-service event cap (default
DEFAULT_MAX_EVENTS_PER_SERVICE). When a service reaches its cap, new
events (by event_id) are skipped; existing event_ids are still updated
on version churn.
Sourcepub fn with_collector_max_logical_keys(self, max_logical_keys: usize) -> Self
pub fn with_collector_max_logical_keys(self, max_logical_keys: usize) -> Self
Replace the underlying collector’s logical-key cap (default
crate::collect::DEFAULT_MAX_LOGICAL_KEYS). See
crate::collect::EitCollector::with_max_logical_keys.
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 event with the earliest start_time strictly after at
(not just the first such event in arbitrary iteration order).
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.