user_preferences: Completed impl of Preference for UserPreferences
from_prefstring_bytes and into_prefstring_bytes are now implemented. Signed-off-by: Ben Aaron Goldberg <ben@benaaron.dev>
This commit is contained in:
parent
ad34aa9a4c
commit
51d5ee9a2e
|
@ -8,6 +8,7 @@ pub mod v0;
|
||||||
mod error;
|
mod error;
|
||||||
pub use error::ParseError;
|
pub use error::ParseError;
|
||||||
|
|
||||||
|
use crate::user_preferences::v0::UserPreferencesV0;
|
||||||
use crate::{InstanceSettings, Pronoun, WeightedTable};
|
use crate::{InstanceSettings, Pronoun, WeightedTable};
|
||||||
|
|
||||||
use data_encoding::BASE32_NOPAD;
|
use data_encoding::BASE32_NOPAD;
|
||||||
|
@ -85,10 +86,22 @@ impl Preference for UserPreferences {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_prefstring_bytes(bytes: &[u8]) -> Result<Self, ParseError> where Self: Sized {
|
fn from_prefstring_bytes(bytes: &[u8]) -> Result<Self, ParseError> 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<u8> {
|
fn into_prefstring_bytes(&self) -> Vec<u8> {
|
||||||
todo!()
|
match self {
|
||||||
|
UserPreferences::V0(pref) => pref,
|
||||||
|
}.into_prefstring_bytes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue