#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
use jacquard_common::deps::bytes::Bytes;
use jacquard_derive::{IntoStatic, open_union};
use serde::{Serialize, Deserialize};
use crate::place_stream::live::subscribe_segments;
#[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()),
)
}
}
}
}
#[derive(
Serialize,
Deserialize,
Debug,
Clone,
PartialEq,
Eq,
thiserror::Error,
miette::Diagnostic
)]
#[serde(tag = "error", content = "message")]
pub enum SubscribeSegmentsError {
#[serde(untagged)]
Other {
error: jacquard_common::deps::smol_str::SmolStr,
message: Option<jacquard_common::deps::smol_str::SmolStr>,
},
}
impl core::fmt::Display for SubscribeSegmentsError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Other { error, message } => {
write!(f, "{}", error)?;
if let Some(msg) = message {
write!(f, ": {}", msg)?;
}
Ok(())
}
}
}
}
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 = SubscribeSegmentsError;
}
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::{Set, Unset, IsSet, IsUnset};
#[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<
St: subscribe_segments_state::State,
S: BosStr = DefaultStr,
> {
_state: PhantomData<fn() -> St>,
_fields: (Option<S>,),
_type: PhantomData<fn() -> S>,
}
impl SubscribeSegments<DefaultStr> {
pub fn new() -> SubscribeSegmentsBuilder<
subscribe_segments_state::Empty,
DefaultStr,
> {
SubscribeSegmentsBuilder::new()
}
}
impl<S: BosStr> SubscribeSegments<S> {
pub fn builder() -> SubscribeSegmentsBuilder<subscribe_segments_state::Empty, S> {
SubscribeSegmentsBuilder::builder()
}
}
impl SubscribeSegmentsBuilder<subscribe_segments_state::Empty, DefaultStr> {
pub fn new() -> Self {
SubscribeSegmentsBuilder {
_state: PhantomData,
_fields: (None,),
_type: PhantomData,
}
}
}
impl<S: BosStr> SubscribeSegmentsBuilder<subscribe_segments_state::Empty, S> {
pub fn builder() -> Self {
SubscribeSegmentsBuilder {
_state: PhantomData,
_fields: (None,),
_type: PhantomData,
}
}
}
impl<St, S: BosStr> SubscribeSegmentsBuilder<St, S>
where
St: subscribe_segments_state::State,
St::Streamer: subscribe_segments_state::IsUnset,
{
pub fn streamer(
mut self,
value: impl Into<S>,
) -> SubscribeSegmentsBuilder<subscribe_segments_state::SetStreamer<St>, S> {
self._fields.0 = Option::Some(value.into());
SubscribeSegmentsBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> SubscribeSegmentsBuilder<St, S>
where
St: subscribe_segments_state::State,
St::Streamer: subscribe_segments_state::IsSet,
{
pub fn build(self) -> SubscribeSegments<S> {
SubscribeSegments {
streamer: self._fields.0.unwrap(),
}
}
}