use async_trait::async_trait;
use bytes::Bytes;
use futures_util::stream::BoxStream;
use crate::error::Result;
pub(crate) fn hashed_channel_for(topic: &str) -> String {
let h = crate::util::sha256_hex(topic.as_bytes());
format!("forge_{}", h.get(..32).unwrap_or(h.as_str()))
}
pub const MAX_TOPIC_BYTES: usize = 256;
pub const MAX_PAYLOAD_BYTES: usize = 7000;
pub type Subscription = BoxStream<'static, Result<Bytes>>;
#[async_trait]
pub trait Pubsub: Send + Sync {
fn channel_for(&self, topic: &str) -> Result<String>;
async fn publish(&self, topic: &str, payload: Bytes) -> Result<()>;
async fn subscribe(&self, topic: &str) -> Result<Subscription>;
}
mod memory;
mod postgres;
pub(crate) use memory::MemPubsub;
pub(crate) use postgres::PgPubsub;