67 lines
1.5 KiB
Rust
67 lines
1.5 KiB
Rust
use std::io;
|
|
|
|
use super::Embeddable;
|
|
use super::IOValue;
|
|
use super::Reader;
|
|
use super::Writer;
|
|
|
|
pub trait DomainDecode<D: Embeddable> {
|
|
fn decode_embedded<'de, 'r, R: Reader<'de>>(
|
|
&mut self,
|
|
r: &'r mut R,
|
|
read_annotations: bool,
|
|
) -> io::Result<D>;
|
|
}
|
|
|
|
pub trait DomainEncode<D: Embeddable> {
|
|
fn encode_embedded<W: Writer>(
|
|
&mut self,
|
|
w: &mut W,
|
|
d: &D,
|
|
) -> io::Result<()>;
|
|
}
|
|
|
|
pub struct IOValueDomainCodec;
|
|
|
|
impl DomainDecode<IOValue> for IOValueDomainCodec {
|
|
fn decode_embedded<'de, 'r, R: Reader<'de>>(
|
|
&mut self,
|
|
r: &'r mut R,
|
|
read_annotations: bool,
|
|
) -> io::Result<IOValue> {
|
|
r.demand_next(read_annotations, self)
|
|
}
|
|
}
|
|
|
|
impl DomainEncode<IOValue> for IOValueDomainCodec {
|
|
fn encode_embedded<W: Writer>(
|
|
&mut self,
|
|
w: &mut W,
|
|
d: &IOValue,
|
|
) -> io::Result<()> {
|
|
w.write(self, d)
|
|
}
|
|
}
|
|
|
|
pub struct NoEmbeddedDomainCodec;
|
|
|
|
impl<D: Embeddable> DomainDecode<D> for NoEmbeddedDomainCodec {
|
|
fn decode_embedded<'de, 'r, R: Reader<'de>>(
|
|
&mut self,
|
|
_r: &'r mut R,
|
|
_read_annotations: bool,
|
|
) -> io::Result<D> {
|
|
Err(io::Error::new(io::ErrorKind::Unsupported, "Embedded values not supported here"))
|
|
}
|
|
}
|
|
|
|
impl<D: Embeddable> DomainEncode<D> for NoEmbeddedDomainCodec {
|
|
fn encode_embedded<W: Writer>(
|
|
&mut self,
|
|
_w: &mut W,
|
|
_d: &D,
|
|
) -> io::Result<()> {
|
|
Err(io::Error::new(io::ErrorKind::Unsupported, "Embedded values not supported here"))
|
|
}
|
|
}
|