-
Notifications
You must be signed in to change notification settings - Fork 430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Serde #189
Merged
Merged
Add Serde #189
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
73ec0f7
Add serde infrastructure
UserAB1236872 44455f0
Isaac Serde
UserAB1236872 b7d04ee
XorShift serde
UserAB1236872 a0248b2
Add a header and remove redundant gate
UserAB1236872 969f411
Feature gate some stuff in Xor test to prevent warnings
UserAB1236872 0ded624
Fix copyright year
UserAB1236872 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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,68 @@ | ||
#[cfg(feature="serde-1")] | ||
pub(super) mod rand_size_serde { | ||
const RAND_SIZE_LEN: usize = 8; | ||
const RAND_SIZE: usize = 1 << RAND_SIZE_LEN; | ||
|
||
use serde::{Deserialize, Deserializer, Serialize, Serializer}; | ||
use serde::de::{Visitor,SeqAccess}; | ||
use serde::de; | ||
|
||
use std::fmt; | ||
|
||
pub fn serialize<T, S>(arr: &[T;RAND_SIZE], ser: S) -> Result<S::Ok, S::Error> | ||
where | ||
T: Serialize, | ||
S: Serializer | ||
{ | ||
use serde::ser::SerializeTuple; | ||
|
||
let mut seq = ser.serialize_tuple(RAND_SIZE)?; | ||
|
||
for e in arr.iter() { | ||
seq.serialize_element(&e)?; | ||
} | ||
|
||
seq.end() | ||
} | ||
|
||
#[inline] | ||
pub fn deserialize<'de, T, D>(de: D) -> Result<[T;RAND_SIZE], D::Error> | ||
where | ||
T: Deserialize<'de>+Default+Copy, | ||
D: Deserializer<'de>, | ||
{ | ||
use std::marker::PhantomData; | ||
struct ArrayVisitor<T> { | ||
_pd: PhantomData<T>, | ||
}; | ||
impl<'de,T> Visitor<'de> for ArrayVisitor<T> | ||
where | ||
T: Deserialize<'de>+Default+Copy | ||
{ | ||
type Value = [T; RAND_SIZE]; | ||
|
||
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { | ||
formatter.write_str("Isaac state array") | ||
} | ||
|
||
#[inline] | ||
fn visit_seq<A>(self, mut seq: A) -> Result<[T; RAND_SIZE], A::Error> | ||
where | ||
A: SeqAccess<'de>, | ||
{ | ||
let mut out = [Default::default();RAND_SIZE]; | ||
|
||
for i in 0..RAND_SIZE { | ||
match seq.next_element()? { | ||
Some(val) => out[i] = val, | ||
None => return Err(de::Error::invalid_length(i, &self)), | ||
}; | ||
} | ||
|
||
Ok(out) | ||
} | ||
} | ||
|
||
de.deserialize_tuple(RAND_SIZE, ArrayVisitor{_pd: PhantomData}) | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file needs a header. Copy the copyright/licence block and add a one-line
//!
comment please.Also I think this
cfg
line is redundant since it was also applied tomod isaac_serde;
.