use crate::place_stream::live::subscribe_segments;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::deps::bytes::Bytes;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
use jacquard_derive::{IntoStatic, open_union};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct SubscribeSegments<S: BosStr = DefaultStr> {
pub streamer: S,
}
#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum SubscribeSegmentsMessage<S: BosStr = DefaultStr> {
#[serde(rename = "#segment")]
Segment(Box<subscribe_segments::Segment>),
}
impl<S: BosStr> SubscribeSegmentsMessage<S> {
pub fn decode_framed<'de>(
bytes: &'de [u8],
) -> Result<SubscribeSegmentsMessage<S>, jacquard_common::error::DecodeError>
where
S: serde::Deserialize<'de>,
{
let (header, body) = jacquard_common::xrpc::subscription::parse_event_header(bytes)?;
match header.t.as_str() {
"#segment" => {
let variant = jacquard_common::deps::codegen::serde_ipld_dagcbor::from_slice(body)?;
Ok(Self::Segment(Box::new(variant)))
}
unknown => Err(jacquard_common::error::DecodeError::UnknownEventType(
unknown.into(),
)),
}
}
}
pub type Segment = Bytes;
pub struct SubscribeSegmentsStream;
impl jacquard_common::xrpc::SubscriptionResp for SubscribeSegmentsStream {
const NSID: &'static str = "place.stream.live.subscribeSegments";
const ENCODING: jacquard_common::xrpc::MessageEncoding =
jacquard_common::xrpc::MessageEncoding::Json;
type Message<S: BosStr> = SubscribeSegmentsMessage<S>;
type Error = jacquard_common::xrpc::GenericError;
}
impl<S: BosStr> jacquard_common::xrpc::XrpcSubscription for SubscribeSegments<S> {
const NSID: &'static str = "place.stream.live.subscribeSegments";
const ENCODING: jacquard_common::xrpc::MessageEncoding =
jacquard_common::xrpc::MessageEncoding::Json;
type Stream = SubscribeSegmentsStream;
}
pub struct SubscribeSegmentsEndpoint;
impl jacquard_common::xrpc::SubscriptionEndpoint for SubscribeSegmentsEndpoint {
const PATH: &'static str = "/xrpc/place.stream.live.subscribeSegments";
const ENCODING: jacquard_common::xrpc::MessageEncoding =
jacquard_common::xrpc::MessageEncoding::Json;
type Params<S: BosStr> = SubscribeSegments<S>;
type Stream = SubscribeSegmentsStream;
}
pub mod subscribe_segments_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Streamer;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Streamer = Unset;
}
pub struct SetStreamer<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetStreamer<St> {}
impl<St: State> State for SetStreamer<St> {
type Streamer = Set<members::streamer>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct streamer(());
}
}
pub struct SubscribeSegmentsBuilder<S: BosStr, St: subscribe_segments_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<S>,),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> SubscribeSegments<S> {
pub fn new() -> SubscribeSegmentsBuilder<S, subscribe_segments_state::Empty> {
SubscribeSegmentsBuilder::new()
}
}
impl<S: BosStr> SubscribeSegmentsBuilder<S, subscribe_segments_state::Empty> {
pub fn new() -> Self {
SubscribeSegmentsBuilder {
_state: PhantomData,
_fields: (None,),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> SubscribeSegmentsBuilder<S, St>
where
St: subscribe_segments_state::State,
St::Streamer: subscribe_segments_state::IsUnset,
{
pub fn streamer(
mut self,
value: impl Into<S>,
) -> SubscribeSegmentsBuilder<S, subscribe_segments_state::SetStreamer<St>> {
self._fields.0 = Option::Some(value.into());
SubscribeSegmentsBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> SubscribeSegmentsBuilder<S, St>
where
St: subscribe_segments_state::State,
St::Streamer: subscribe_segments_state::IsSet,
{
pub fn build(self) -> SubscribeSegments<S> {
SubscribeSegments {
streamer: self._fields.0.unwrap(),
}
}
}