Skip to content

Commit 4556d4c

Browse files
committed
refactor: streamline imports and improve data handling in helper and parser modules
1 parent 4697d25 commit 4556d4c

3 files changed

Lines changed: 12 additions & 20 deletions

File tree

src/helper.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
use crate::{
2-
parser::{decode_action, LiqiMessage},
3-
settings::Settings,
42
ARBITRARY_MD5,
3+
parser::{LiqiMessage, decode_action},
4+
settings::Settings,
55
};
66
use anyhow::{Context, Result};
77
use reqwest::Client;
88
use serde::Serialize;
9-
use serde_json::{json, Map, Value as JsonValue};
10-
use std::{
11-
borrow::Cow,
12-
future::Future,
13-
sync::{Arc, LazyLock},
14-
};
9+
use serde_json::{Map, Value as JsonValue, json};
10+
use std::{borrow::Cow, future::Future, sync::LazyLock};
1511
use tokio::{spawn, sync::mpsc::Receiver, time::sleep};
1612
use tracing::{debug, error, info};
1713

@@ -61,17 +57,13 @@ fn process_message(mut parsed: LiqiMessage, settings: &Settings) -> Result<()> {
6157
return Ok(());
6258
}
6359
if name == "ActionNewRound" {
64-
Arc::<serde_json::Value>::make_mut(&mut parsed.data)["data"]
60+
parsed
61+
.data
6562
.as_object_mut()
6663
.context("data field invalid")?
6764
.insert("md5".to_string(), json!(ARBITRARY_MD5));
6865
}
69-
Cow::Owned(
70-
Arc::<serde_json::Value>::make_mut(&mut parsed.data)
71-
.get_mut("data")
72-
.context("No data field")?
73-
.take(),
74-
)
66+
Cow::Owned(parsed.data.get_mut("data").context("No data field")?.take())
7567
}
7668
".lq.FastTest.syncGame" => {
7769
let game_restore = parsed.data["game_restore"]["actions"]

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mod handler;
1313
mod helper;
1414
mod modder;
1515
mod parser;
16-
pub(crate) mod proto;
16+
mod proto;
1717
mod settings;
1818

1919
pub use crate::{

src/parser.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use anyhow::{ensure, Context, Result};
1+
use anyhow::{Context, Result, ensure};
22
use base64::prelude::*;
33
use bytes::Bytes;
44
use prost::Message;
55
use prost_reflect::{DescriptorPool, DynamicMessage, MessageDescriptor, SerializeOptions};
6-
use serde_json::{value::Serializer, Value as JsonValue};
6+
use serde_json::{Value as JsonValue, value::Serializer};
77
use std::{collections::HashMap, sync::Arc};
88

99
use crate::proto::base::BaseMessage;
@@ -24,7 +24,7 @@ pub struct LiqiMessage {
2424
pub id: usize,
2525
pub msg_type: MessageType,
2626
pub method_name: Arc<str>,
27-
pub data: Arc<JsonValue>,
27+
pub data: JsonValue,
2828
}
2929

3030
impl LiqiMessage {
@@ -33,7 +33,7 @@ impl LiqiMessage {
3333
id,
3434
msg_type,
3535
method_name,
36-
data: Arc::new(data),
36+
data,
3737
}
3838
}
3939
}

0 commit comments

Comments
 (0)