use serde::{Deserialize, Serialize};
use std::fmt::Display;
use crate::Packet;
use crate::bytes::Bytes;
use crate::error::Error;
use crate::message::{ContentType, MetaDataType};
use crate::ron::{FromRon, ToRon};
use super::message::{Context, Output};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Content(String);
impl Default for Content {
fn default() -> Self {
Self::empty()
}
}
impl FromRon<'_> for Content {}
impl ToRon for Content {}
impl Display for Content {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Content({})", self.string_ref())
}
}
impl TryFrom<Bytes> for Content {
type Error = Error;
fn try_from(value: Bytes) -> Result<Self, Self::Error> {
todo!()
}
}
impl TryFrom<Content> for Bytes {
type Error = Error;
fn try_from(value: Content) -> Result<Self, Self::Error> {
todo!()
}
}
impl<'a, M> ContentType<'a, M, Content> for Content
where
M: MetaDataType<'a, M, Content>,
{
type SendContext = Context;
type ReceiveContext = Context;
type SendOutput = Output;
type ReceiveOutput = Output;
fn send(
self,
stream: &mut std::net::TcpStream,
context: Option<Self::SendContext>,
) -> Result<Option<Self::SendOutput>, Error> {
todo!()
}
fn receive(
stream: &mut std::net::TcpStream,
metadata: &M,
context: Option<Self::ReceiveContext>,
) -> Result<
(
Self,
Packet,
Option<<Content as ContentType<'a, M, Content>>::ReceiveOutput>,
),
Error,
> {
todo!()
}
}
impl Content {
pub fn new(data: String) -> Self {
Content(data)
}
pub fn empty() -> Self {
Content(String::new())
}
pub fn string_ref(&self) -> &String {
&self.0
}
}