Implement bounded Binary LLSD codec
This commit is contained in:
@@ -188,7 +188,7 @@ impl OSD {
|
||||
Self::Real(value) => value.to_be_bytes().to_vec(),
|
||||
Self::String(value) | Self::LlsdXml(value) => value.as_bytes().to_vec(),
|
||||
Self::UUID(value) => value.get_bytes()?,
|
||||
Self::Date(value) => unix_seconds_f64(*value).to_le_bytes().to_vec(),
|
||||
Self::Date(value) => unix_seconds_for_codec(*value).to_le_bytes().to_vec(),
|
||||
Self::Uri(value) => value.0.as_bytes().to_vec(),
|
||||
Self::Binary(value) => value.clone(),
|
||||
Self::Array(values) => values
|
||||
@@ -842,7 +842,7 @@ impl OSDUUID {
|
||||
scalar_wrapper!(OSDDate, SystemTime, Date, Date);
|
||||
impl OSDDate {
|
||||
pub fn as_binary(&self) -> Result<Vec<u8>, Error> {
|
||||
Ok(unix_seconds_f64(self.value).to_le_bytes().to_vec())
|
||||
Ok(unix_seconds_for_codec(self.value).to_le_bytes().to_vec())
|
||||
}
|
||||
pub const fn as_date(&self) -> Result<SystemTime, Error> {
|
||||
Ok(self.value)
|
||||
@@ -1425,7 +1425,7 @@ fn format_real(value: f64) -> String {
|
||||
value.to_string()
|
||||
}
|
||||
}
|
||||
fn unix_seconds_f64(value: SystemTime) -> f64 {
|
||||
pub(crate) fn unix_seconds_for_codec(value: SystemTime) -> f64 {
|
||||
match value.duration_since(UNIX_EPOCH) {
|
||||
Ok(duration) => duration.as_secs_f64(),
|
||||
Err(error) => -error.duration().as_secs_f64(),
|
||||
|
||||
Reference in New Issue
Block a user