Created
May 24, 2017 13:34
-
-
Save zackw/7bb9f12c5509850ccae35a75a2fac791 to your computer and use it in GitHub Desktop.
I think this works
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
pub fn deserialize(bytes: &[u8]) -> Result<Self, AlchemistError> { | |
let key_length = bytestou32(&bytes[0..4]) as usize; | |
let value_length = bytestou32(&bytes[4..8]) as usize; | |
let maybe_key = String::from_utf8(bytes[8 .. 8 + key_length].to_vec()); | |
let maybe_value = String::from_utf8(bytes[8 + key_length .. 8 + key_length + value_length].to_vec()) | |
match (maybe_key, maybe_value) { | |
(Ok(ref key), Ok(ref value)) => Ok(Self::new(key, value)), | |
_ => Err(AlchemistError::DeserializationFailed) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment