diff --git a/proto/backend.proto b/proto/backend.proto index 280f6d6bd..bcbad1ba2 100644 --- a/proto/backend.proto +++ b/proto/backend.proto @@ -99,10 +99,10 @@ message BackendOutput { GetCardOut get_card = 38; Empty update_card = 39; int64 add_card = 40; - string get_deck_config = 41; + bytes get_deck_config = 41; int64 add_or_update_deck_config = 42; - string all_deck_config = 43; - string new_deck_config = 44; + bytes all_deck_config = 43; + bytes new_deck_config = 44; Empty remove_deck_config = 45; Empty before_upload = 47; bool register_tags = 48; @@ -434,7 +434,7 @@ message CloseCollectionIn { } message AddOrUpdateDeckConfigIn { - string config = 1; + bytes config = 1; bool preserve_usn_and_mtime = 2; } diff --git a/pylib/anki/rsbackend.py b/pylib/anki/rsbackend.py index 2449fbab8..e67b463c2 100644 --- a/pylib/anki/rsbackend.py +++ b/pylib/anki/rsbackend.py @@ -510,10 +510,10 @@ class RustBackend: def get_deck_config(self, dcid: int) -> Dict[str, Any]: jstr = self._run_command(pb.BackendInput(get_deck_config=dcid)).get_deck_config - return json.loads(jstr) + return orjson.loads(jstr) def add_or_update_deck_config(self, conf: Dict[str, Any], preserve_usn) -> None: - conf_json = json.dumps(conf) + conf_json = orjson.dumps(conf) id = self._run_command( pb.BackendInput( add_or_update_deck_config=pb.AddOrUpdateDeckConfigIn( @@ -527,13 +527,13 @@ class RustBackend: jstr = self._run_command( pb.BackendInput(all_deck_config=pb.Empty()) ).all_deck_config - return json.loads(jstr) + return orjson.loads(jstr) def new_deck_config(self) -> Dict[str, Any]: jstr = self._run_command( pb.BackendInput(new_deck_config=pb.Empty()) ).new_deck_config - return json.loads(jstr) + return orjson.loads(jstr) def remove_deck_config(self, dcid: int) -> None: self._run_command(pb.BackendInput(remove_deck_config=dcid)) diff --git a/rslib/src/backend/mod.rs b/rslib/src/backend/mod.rs index 7452a624e..4178373db 100644 --- a/rslib/src/backend/mod.rs +++ b/rslib/src/backend/mod.rs @@ -717,15 +717,15 @@ impl Backend { Ok(card.id.0) } - fn get_deck_config(&self, dcid: i64) -> Result { + fn get_deck_config(&self, dcid: i64) -> Result> { self.with_col(|col| { let conf = col.get_deck_config(DeckConfID(dcid), true)?.unwrap(); - Ok(serde_json::to_string(&conf)?) + Ok(serde_json::to_vec(&conf)?) }) } fn add_or_update_deck_config(&self, input: AddOrUpdateDeckConfigIn) -> Result { - let mut conf: DeckConf = serde_json::from_str(&input.config)?; + let mut conf: DeckConf = serde_json::from_slice(&input.config)?; self.with_col(|col| { col.transact(None, |col| { col.add_or_update_deck_config(&mut conf, input.preserve_usn_and_mtime)?; @@ -734,14 +734,12 @@ impl Backend { }) } - fn all_deck_config(&self) -> Result { - self.with_col(|col| { - serde_json::to_string(&col.storage.all_deck_config()?).map_err(Into::into) - }) + fn all_deck_config(&self) -> Result> { + self.with_col(|col| serde_json::to_vec(&col.storage.all_deck_config()?).map_err(Into::into)) } - fn new_deck_config(&self) -> Result { - serde_json::to_string(&DeckConf::default()).map_err(Into::into) + fn new_deck_config(&self) -> Result> { + serde_json::to_vec(&DeckConf::default()).map_err(Into::into) } fn remove_deck_config(&self, dcid: i64) -> Result<()> {