mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 02:35:31 +00:00
aquatic ws: deserialize OutMessage properly
Performance seems to be about the same
This commit is contained in:
parent
dea88020a5
commit
884a2aa67d
1 changed files with 3 additions and 15 deletions
|
|
@ -283,10 +283,10 @@ impl InMessage {
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum OutMessage {
|
pub enum OutMessage {
|
||||||
AnnounceResponse(AnnounceResponse),
|
|
||||||
ScrapeResponse(ScrapeResponse),
|
|
||||||
Offer(MiddlemanOfferToPeer),
|
Offer(MiddlemanOfferToPeer),
|
||||||
Answer(MiddlemanAnswerToPeer),
|
Answer(MiddlemanAnswerToPeer),
|
||||||
|
AnnounceResponse(AnnounceResponse),
|
||||||
|
ScrapeResponse(ScrapeResponse),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -308,19 +308,7 @@ impl OutMessage {
|
||||||
_ => return Err(anyhow::anyhow!("Message is neither text nor bytes")),
|
_ => return Err(anyhow::anyhow!("Message is neither text nor bytes")),
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is brittle and could fail, but it doesn't matter too much
|
Ok(::simd_json::serde::from_str(&mut text)?)
|
||||||
// since this function is only used in load tester
|
|
||||||
if text.contains("answer"){
|
|
||||||
Ok(Self::Answer(::simd_json::serde::from_str(&mut text)?))
|
|
||||||
} else if text.contains("offer"){
|
|
||||||
Ok(Self::Offer(::simd_json::serde::from_str(&mut text)?))
|
|
||||||
} else if text.contains("interval"){
|
|
||||||
Ok(Self::AnnounceResponse(::simd_json::serde::from_str(&mut text)?))
|
|
||||||
} else if text.contains("scrape"){
|
|
||||||
Ok(Self::ScrapeResponse(::simd_json::serde::from_str(&mut text)?))
|
|
||||||
} else {
|
|
||||||
Err(anyhow::anyhow!("Could not determine response type"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue