2021-07-05 10:38:11 +00:00
|
|
|
use std::io;
|
|
|
|
|
2021-07-04 15:16:13 +00:00
|
|
|
use super::Embeddable;
|
|
|
|
use super::IOValue;
|
2021-07-05 09:50:40 +00:00
|
|
|
use super::Reader;
|
2021-07-05 10:34:29 +00:00
|
|
|
use super::Writer;
|
2021-08-02 09:42:48 +00:00
|
|
|
|
2021-07-04 15:16:13 +00:00
|
|
|
pub trait DomainDecode<D: Embeddable> {
|
2022-07-10 11:25:35 +00:00
|
|
|
fn decode_embedded<'de, 'r, R: Reader<'de>>(
|
2021-07-05 09:50:40 +00:00
|
|
|
&mut self,
|
2022-07-10 11:25:35 +00:00
|
|
|
r: &'r mut R,
|
2021-07-05 09:50:40 +00:00
|
|
|
read_annotations: bool,
|
2021-07-05 10:38:11 +00:00
|
|
|
) -> io::Result<D>;
|
2021-07-04 15:16:13 +00:00
|
|
|
}
|
|
|
|
|
2021-07-05 10:34:29 +00:00
|
|
|
pub trait DomainEncode<D: Embeddable> {
|
|
|
|
fn encode_embedded<W: Writer>(
|
|
|
|
&mut self,
|
|
|
|
w: &mut W,
|
|
|
|
d: &D,
|
2021-07-05 10:38:11 +00:00
|
|
|
) -> io::Result<()>;
|
2021-07-05 10:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct IOValueDomainCodec;
|
2021-07-04 15:16:13 +00:00
|
|
|
|
2021-07-05 10:34:29 +00:00
|
|
|
impl DomainDecode<IOValue> for IOValueDomainCodec {
|
2022-07-10 11:25:35 +00:00
|
|
|
fn decode_embedded<'de, 'r, R: Reader<'de>>(
|
2021-07-05 09:50:40 +00:00
|
|
|
&mut self,
|
2022-07-10 11:25:35 +00:00
|
|
|
r: &'r mut R,
|
2021-07-05 09:50:40 +00:00
|
|
|
read_annotations: bool,
|
2021-07-05 10:38:11 +00:00
|
|
|
) -> io::Result<IOValue> {
|
2022-07-10 11:25:35 +00:00
|
|
|
r.demand_next(read_annotations, self)
|
2021-07-05 10:34:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DomainEncode<IOValue> for IOValueDomainCodec {
|
|
|
|
fn encode_embedded<W: Writer>(
|
|
|
|
&mut self,
|
|
|
|
w: &mut W,
|
|
|
|
d: &IOValue,
|
2021-07-05 10:38:11 +00:00
|
|
|
) -> io::Result<()> {
|
2021-07-05 10:34:29 +00:00
|
|
|
w.write(self, d)
|
2021-07-04 15:16:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-05 10:34:29 +00:00
|
|
|
pub struct NoEmbeddedDomainCodec;
|
2021-07-04 15:16:13 +00:00
|
|
|
|
2021-07-05 10:34:29 +00:00
|
|
|
impl<D: Embeddable> DomainDecode<D> for NoEmbeddedDomainCodec {
|
2022-07-10 11:25:35 +00:00
|
|
|
fn decode_embedded<'de, 'r, R: Reader<'de>>(
|
2021-07-05 09:50:40 +00:00
|
|
|
&mut self,
|
2022-07-10 11:25:35 +00:00
|
|
|
_r: &'r mut R,
|
2021-07-05 09:50:40 +00:00
|
|
|
_read_annotations: bool,
|
2021-07-05 10:38:11 +00:00
|
|
|
) -> io::Result<D> {
|
2021-07-05 11:00:30 +00:00
|
|
|
Err(io::Error::new(io::ErrorKind::Unsupported, "Embedded values not supported here"))
|
2021-07-04 15:16:13 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-05 10:34:29 +00:00
|
|
|
|
|
|
|
impl<D: Embeddable> DomainEncode<D> for NoEmbeddedDomainCodec {
|
|
|
|
fn encode_embedded<W: Writer>(
|
|
|
|
&mut self,
|
|
|
|
_w: &mut W,
|
|
|
|
_d: &D,
|
2021-07-05 10:38:11 +00:00
|
|
|
) -> io::Result<()> {
|
2021-07-05 11:00:30 +00:00
|
|
|
Err(io::Error::new(io::ErrorKind::Unsupported, "Embedded values not supported here"))
|
2021-07-05 10:34:29 +00:00
|
|
|
}
|
|
|
|
}
|