-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add postcard support to FsDataProvider (#1606)
- Loading branch information
Showing
7 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
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
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
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,41 @@ | ||
// This file is part of ICU4X. For terms of use, please see the file | ||
// called LICENSE at the top level of the ICU4X source tree | ||
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). | ||
|
||
use super::AbstractSerializer; | ||
use super::Error; | ||
use icu_provider::buf::BufferFormat; | ||
use std::io; | ||
|
||
/// A serializer for Postcard. | ||
pub struct Serializer; | ||
|
||
/// Options bag for initializing a [`postcard::Serializer`]. | ||
#[non_exhaustive] | ||
#[derive(Clone, Debug, PartialEq, Default)] | ||
pub struct Options; | ||
|
||
impl AbstractSerializer for Serializer { | ||
fn serialize( | ||
&self, | ||
obj: &dyn erased_serde::Serialize, | ||
sink: &mut dyn io::Write, | ||
) -> Result<(), Error> { | ||
let mut serializer = postcard::Serializer { | ||
output: postcard::flavors::StdVec(Vec::new()), | ||
}; | ||
obj.erased_serialize(&mut <dyn erased_serde::Serializer>::erase(&mut serializer))?; | ||
sink.write_all(&serializer.output.0)?; | ||
Ok(()) | ||
} | ||
|
||
fn get_buffer_format(&self) -> BufferFormat { | ||
BufferFormat::Postcard07 | ||
} | ||
} | ||
|
||
impl Serializer { | ||
pub fn new(_options: Options) -> Self { | ||
Self {} | ||
} | ||
} |
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