Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upMake Reader and Writer generic on Endianness #103
Conversation
| @@ -69,7 +70,7 @@ pub fn serialize<T>(value: &T, size_limit: SizeLimit) -> SerializeResult<Vec<u8> | |||
| SizeLimit::Infinite => Vec::new() | |||
| }; | |||
|
|
|||
| try!(serialize_into(&mut writer, value, SizeLimit::Infinite)); | |||
| try!(serialize_into::<_, _, ::byteorder::BigEndian>(&mut writer, value, SizeLimit::Infinite)); | |||
This comment has been minimized.
This comment has been minimized.
| @@ -107,7 +108,7 @@ pub fn deserialize_from<R, T>(reader: &mut R, size_limit: SizeLimit) -> Deserial | |||
| where R: Read, | |||
| T: serde::Deserialize, | |||
| { | |||
| let mut deserializer = Deserializer::new(reader, size_limit); | |||
| let mut deserializer = Deserializer::<_, BigEndian>::new(reader, size_limit); | |||
This comment has been minimized.
This comment has been minimized.
|
@aldanor: in its current state, this PR adds endian genericness to the backend, but not the public functions. That will change in the future, but I wanted to get the difficult part passing tests first. |
aldanor
commented
Feb 5, 2017
|
@TyOverby I see then, thanks; looks good to me given that this will be later exposed to the crate-level functions. // Should there be some explicit tests for big/little endian? |
|
@aldanor: I've gone with the decision to add an |
|
Oh, also, I've picked LittleEndian as the new default endianness (mainly for speed on the average computer) |
…endian encoding
| let x = 10u64; | ||
| let little = serialize::<_, byteorder::LittleEndian>(&x, Infinite).unwrap(); | ||
| let big = serialize::<_, byteorder::BigEndian>(&x, Infinite).unwrap(); | ||
| assert!(little != big); |
This comment has been minimized.
This comment has been minimized.
ZoeyR
Feb 10, 2017
Collaborator
Wouldn't it be better to use assert_ne!(little, big);? As I understand it you get better error messages that way.
This comment has been minimized.
This comment has been minimized.
aldanor
commented
Feb 11, 2017
|
That's one way to go about it I guess. Little endian as a default sounds grand; worth mentioning in the docstrings of the root module somewhere? |
While introducing selectable endianness in servo#103 , the new type parameter has been hidden from the public `serialize()`, `deserialize()` etc. functions, and only made available through an alternate API entry point. The same kind of encapsulation also needs to be performed for the public `Serializer` and `Deserializer` types.
…128) While introducing selectable endianness in #103 , the new type parameter has been hidden from the public `serialize()`, `deserialize()` etc. functions, and only made available through an alternate API entry point. The same kind of encapsulation also needs to be performed for the public `Serializer` and `Deserializer` types.
TyOverby commentedFeb 1, 2017
No description provided.