diff --git a/src/user_preferences/mod.rs b/src/user_preferences/mod.rs index e176ac2..08ef286 100644 --- a/src/user_preferences/mod.rs +++ b/src/user_preferences/mod.rs @@ -8,6 +8,7 @@ pub mod v0; mod error; pub use error::ParseError; +use crate::user_preferences::v0::UserPreferencesV0; use crate::{InstanceSettings, Pronoun, WeightedTable}; use data_encoding::BASE32_NOPAD; @@ -85,10 +86,22 @@ impl Preference for UserPreferences { } fn from_prefstring_bytes(bytes: &[u8]) -> Result where Self: Sized { - todo!() + let version_byte = bytes.get(0).ok_or(ParseError::ZeroLengthPrefstring)?; + let version = version_byte >> 3; + let varient = version_byte & 0b111; + match (version, varient) { + (0, 0) => UserPreferencesV0::from_prefstring_bytes(bytes).map(|prefs| UserPreferences::V0(prefs)), + _ => Err(ParseError::VersionMismatch { + expected_version: 0..1, + expected_variant: 0..1, + actual_version_byte: *version_byte, + }) + } } fn into_prefstring_bytes(&self) -> Vec { - todo!() + match self { + UserPreferences::V0(pref) => pref, + }.into_prefstring_bytes() } }