diff options
| author | metamuffin <metamuffin@disroot.org> | 2026-02-18 03:41:05 +0100 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2026-02-18 03:41:05 +0100 |
| commit | b39e1a10c731fd0e61a566a0668abc33ae821b49 (patch) | |
| tree | 6e2e48b5e56a2cf4b4f966b6f2e014c446a242a1 /common/object/src/json.rs | |
| parent | 95606a9deed45ae285c2d4dee01de9d21a43b044 (diff) | |
| download | jellything-b39e1a10c731fd0e61a566a0668abc33ae821b49.tar jellything-b39e1a10c731fd0e61a566a0668abc33ae821b49.tar.bz2 jellything-b39e1a10c731fd0e61a566a0668abc33ae821b49.tar.zst | |
use fourcc as object tags (bad idea); store type info within objects
Diffstat (limited to 'common/object/src/json.rs')
| -rw-r--r-- | common/object/src/json.rs | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/common/object/src/json.rs b/common/object/src/json.rs index 0aa4cbd..cbb8bda 100644 --- a/common/object/src/json.rs +++ b/common/object/src/json.rs @@ -4,36 +4,30 @@ Copyright (C) 2026 metamuffin <metamuffin.org> */ -use crate::{Object, Registry, types::*}; +use crate::{Object, ValueType}; use serde_json::{Map, Value}; -pub fn object_to_json(reg: &Registry, ob: Object<'_>) -> Value { +pub fn object_to_json(ob: Object<'_>) -> Value { let mut o = Map::new(); let mut nonexhaustive = false; for (i, tag) in ob.keys().enumerate() { - let Some(info) = reg.info(tag) else { - nonexhaustive = true; - continue; - }; - let Some(ty) = info.r#type else { - nonexhaustive = true; - continue; - }; - let key = info.name.to_string(); - - let val = match ty { - x if x == STR => ob.get_typed::<&str>(i).unwrap().to_string().into(), - x if x == OBJECT => object_to_json(reg, ob.get_typed::<Object>(i).unwrap()), - x if x == U32 => ob.get_typed::<u32>(i).unwrap().into(), - x if x == U64 => ob.get_typed::<u64>(i).unwrap().into(), - x if x == I64 => ob.get_typed::<i64>(i).unwrap().into(), - x if x == F64 => ob.get_typed::<f64>(i).unwrap().into(), + let kbytes = tag.0.to_be_bytes(); + let k = str::from_utf8(&kbytes).unwrap().to_string(); + let ty = ob.offset_type(i); + let sz = ob.size(i); + let val = match (ty, sz) { + (ValueType::String, _) => ob.get_typed::<&str>(i).unwrap().to_string().into(), + (ValueType::Object, _) => object_to_json(ob.get_typed::<Object>(i).unwrap()), + (ValueType::UInt, 4) => ob.get_typed::<u32>(i).unwrap().into(), + (ValueType::UInt, 8) => ob.get_typed::<u64>(i).unwrap().into(), + (ValueType::Int, 8) => ob.get_typed::<i64>(i).unwrap().into(), + (ValueType::Float, 8) => ob.get_typed::<f64>(i).unwrap().into(), _ => { nonexhaustive = true; continue; } }; - multi_insert(&mut o, key, val); + multi_insert(&mut o, k, val); } if nonexhaustive { o.insert("_nonexhaustive".to_owned(), Value::Bool(true)); |