-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,4 @@ architectures. | |
| TOML | ✔️ | ✔️ | | ||
| Raw (plain text) | ✔️ | ✔️ | | ||
| CSV | ✔️ | ✔️ | | ||
| SMILE | ✔️ | ✔️ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use crate::error; | ||
|
||
use crate::value; | ||
use serde; | ||
use serde_smile; | ||
use std::fmt; | ||
use std::io; | ||
|
||
pub struct Source<R>( | ||
serde_smile::de::StreamDeserializer< | ||
'static, | ||
serde_smile::de::IoRead<io::BufReader<R>>, | ||
value::Value, | ||
>, | ||
) | ||
where | ||
R: io::Read; | ||
|
||
pub struct Sink<W>(serde_smile::ser::Serializer<W>) | ||
where | ||
W: io::Write; | ||
|
||
#[inline] | ||
pub fn source<R>(r: R) -> error::Result<Source<R>> | ||
where | ||
R: io::Read, | ||
{ | ||
Ok(Source( | ||
serde_smile::de::Deserializer::new(serde_smile::de::IoRead::new(io::BufReader::new(r)))? | ||
.into_iter(), | ||
)) | ||
} | ||
|
||
#[inline] | ||
pub fn sink<W>(w: W) -> error::Result<Sink<W>> | ||
where | ||
W: io::Write, | ||
{ | ||
Ok(Sink( | ||
serde_smile::ser::Serializer::builder() | ||
.shared_strings(true) | ||
.build(w)?, | ||
)) | ||
} | ||
|
||
impl<R> value::Source for Source<R> | ||
where | ||
R: io::Read, | ||
{ | ||
#[inline] | ||
fn read(&mut self) -> error::Result<Option<value::Value>> { | ||
Ok(self.0.next().transpose()?) | ||
} | ||
} | ||
|
||
impl<W> value::Sink for Sink<W> | ||
where | ||
W: io::Write, | ||
{ | ||
#[inline] | ||
fn write(&mut self, v: value::Value) -> error::Result<()> { | ||
Ok(serde::Serialize::serialize(&v, &mut self.0)?) | ||
} | ||
} | ||
|
||
impl<R> fmt::Debug for Source<R> | ||
where | ||
R: io::Read, | ||
{ | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
f.debug_struct("SmileSource").finish() | ||
} | ||
} | ||
|
||
impl<W> fmt::Debug for Sink<W> | ||
where | ||
W: io::Write, | ||
{ | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
f.debug_struct("SmileSink").finish() | ||
} | ||
} |