Implement StructuredData OSD model and containers

This commit is contained in:
2026-08-09 00:10:12 +00:00
parent ae0b7966e2
commit d152e80ef9
15 changed files with 2408 additions and 1456 deletions

View File

@@ -22,7 +22,19 @@ impl<T: std::io::Read + std::io::Write> ReadWrite for T {}
#[derive(Clone, Debug)]
pub enum Object {
Undefined,
Boolean(bool),
Integer(i32),
UInteger(u32),
Long(i64),
ULong(u64),
Real(f64),
Color4(crate::Color4),
Date(std::time::SystemTime),
Bytes(Vec<u8>),
Uri(Uri),
Array(Vec<Object>),
Map(std::collections::HashMap<String, Object>),
Matrix4(crate::Matrix4),
Quaternion(crate::Quaternion),
String(String),
@@ -36,6 +48,18 @@ pub enum Object {
impl PartialEq for Object {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Undefined, Self::Undefined) => true,
(Self::Boolean(lhs), Self::Boolean(rhs)) => lhs == rhs,
(Self::Integer(lhs), Self::Integer(rhs)) => lhs == rhs,
(Self::UInteger(lhs), Self::UInteger(rhs)) => lhs == rhs,
(Self::Long(lhs), Self::Long(rhs)) => lhs == rhs,
(Self::ULong(lhs), Self::ULong(rhs)) => lhs == rhs,
(Self::Real(lhs), Self::Real(rhs)) => lhs.to_bits() == rhs.to_bits(),
(Self::Date(lhs), Self::Date(rhs)) => lhs == rhs,
(Self::Bytes(lhs), Self::Bytes(rhs)) => lhs == rhs,
(Self::Uri(lhs), Self::Uri(rhs)) => lhs == rhs,
(Self::Array(lhs), Self::Array(rhs)) => lhs == rhs,
(Self::Map(lhs), Self::Map(rhs)) => lhs == rhs,
(Self::Color4(lhs), Self::Color4(rhs)) => crate::Color4::eq(*lhs, *rhs),
(Self::Matrix4(lhs), Self::Matrix4(rhs)) => crate::Matrix4::eq(*lhs, *rhs),
(Self::Quaternion(lhs), Self::Quaternion(rhs)) => crate::Quaternion::eq(*lhs, *rhs),
@@ -56,6 +80,22 @@ impl std::hash::Hash for Object {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
std::mem::discriminant(self).hash(state);
match self {
Self::Undefined => {}
Self::Boolean(value) => value.hash(state),
Self::Integer(value) => value.hash(state),
Self::UInteger(value) => value.hash(state),
Self::Long(value) => value.hash(state),
Self::ULong(value) => value.hash(state),
Self::Real(value) => value.to_bits().hash(state),
Self::Date(value) => value.hash(state),
Self::Bytes(value) => value.hash(state),
Self::Uri(value) => value.hash(state),
Self::Array(value) => value.hash(state),
Self::Map(value) => {
let mut entries: Vec<_> = value.iter().collect();
entries.sort_unstable_by_key(|(key, _)| *key);
entries.hash(state);
}
Self::Color4(value) => value.get_hash_code().hash(state),
Self::Matrix4(value) => value.get_hash_code().hash(state),
Self::Quaternion(value) => value.get_hash_code().hash(state),