mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
use bytes for deck config proto
This commit is contained in:
parent
164bd29438
commit
dc62d5072c
3 changed files with 15 additions and 17 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -717,15 +717,15 @@ impl Backend {
|
|||
Ok(card.id.0)
|
||||
}
|
||||
|
||||
fn get_deck_config(&self, dcid: i64) -> Result<String> {
|
||||
fn get_deck_config(&self, dcid: i64) -> Result<Vec<u8>> {
|
||||
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<i64> {
|
||||
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<String> {
|
||||
self.with_col(|col| {
|
||||
serde_json::to_string(&col.storage.all_deck_config()?).map_err(Into::into)
|
||||
})
|
||||
fn all_deck_config(&self) -> Result<Vec<u8>> {
|
||||
self.with_col(|col| serde_json::to_vec(&col.storage.all_deck_config()?).map_err(Into::into))
|
||||
}
|
||||
|
||||
fn new_deck_config(&self) -> Result<String> {
|
||||
serde_json::to_string(&DeckConf::default()).map_err(Into::into)
|
||||
fn new_deck_config(&self) -> Result<Vec<u8>> {
|
||||
serde_json::to_vec(&DeckConf::default()).map_err(Into::into)
|
||||
}
|
||||
|
||||
fn remove_deck_config(&self, dcid: i64) -> Result<()> {
|
||||
|
|
Loading…
Reference in a new issue