Skip to main content

EpgStore

Struct EpgStore 

Source
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

Source

pub fn new() -> Self

Create a new, empty EPG store with default caps (DEFAULT_MAX_SERVICES, DEFAULT_MAX_EVENTS_PER_SERVICE).

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn feed_with_pid( &mut self, pid: Option<u16>, bytes: &[u8], ) -> CollectResult<()>

Feed one EIT section with PID context into the store.

Source

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.

Source

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.

Source

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.

Source

pub fn service_name(&self, key: ServiceKey) -> Option<&str>

Return the service name for a given key, if SDT data was fed.

Source

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.

Source

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).

Source

pub fn service_count(&self) -> usize

Return the number of services with cached EIT data.

Source

pub fn event_count(&self) -> usize

Return the total number of events across all services.

Source

pub fn retain_services<F>(&mut self, keep: F)
where F: FnMut(&ServiceKey) -> bool,

Retain only services matching the given predicate.

Both the event cache and the underlying collector partial state for rejected keys are removed.

Source

pub fn clear(&mut self)

Clear all cached EIT data and reset the internal collector.

Trait Implementations§

Source§

impl Debug for EpgStore

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EpgStore

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Serialize for EpgStore

Available on crate feature serde only.
Source§

fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> DescriptorObject for T
where T: Debug + Any + Send + Sync + Serialize,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Borrow as &dyn Any so the caller can downcast to the concrete type.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> ExtensionObject for T
where T: Debug + Any + Send + Sync + Serialize,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Borrow as &dyn Any so the caller can downcast to the concrete type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> TableObject for T
where T: Debug + Any + Send + Sync + Serialize,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Borrow as &dyn Any so the caller can downcast to the concrete type.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.