mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
ws: update simd-json to 0.10.3
This commit is contained in:
parent
8734855c49
commit
fca6cc9fbd
6 changed files with 145 additions and 60 deletions
77
Cargo.lock
generated
77
Cargo.lock
generated
|
|
@ -1111,9 +1111,9 @@ checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "halfbrown"
|
name = "halfbrown"
|
||||||
version = "0.1.18"
|
version = "0.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9e2a3c70a9c00cc1ee87b54e89f9505f73bb17d63f1b25c9a462ba8ef885444f"
|
checksum = "f985624e90f861184145c13b736873a0f83cdb998a292dbb0653598ab03aecbf"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hashbrown 0.13.2",
|
"hashbrown 0.13.2",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
@ -1358,6 +1358,70 @@ version = "1.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lexical-core"
|
||||||
|
version = "0.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2cde5de06e8d4c2faabc400238f9ae1c74d5412d03a7bd067645ccbc47070e46"
|
||||||
|
dependencies = [
|
||||||
|
"lexical-parse-float",
|
||||||
|
"lexical-parse-integer",
|
||||||
|
"lexical-util",
|
||||||
|
"lexical-write-float",
|
||||||
|
"lexical-write-integer",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lexical-parse-float"
|
||||||
|
version = "0.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "683b3a5ebd0130b8fb52ba0bdc718cc56815b6a097e28ae5a6997d0ad17dc05f"
|
||||||
|
dependencies = [
|
||||||
|
"lexical-parse-integer",
|
||||||
|
"lexical-util",
|
||||||
|
"static_assertions",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lexical-parse-integer"
|
||||||
|
version = "0.8.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6d0994485ed0c312f6d965766754ea177d07f9c00c9b82a5ee62ed5b47945ee9"
|
||||||
|
dependencies = [
|
||||||
|
"lexical-util",
|
||||||
|
"static_assertions",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lexical-util"
|
||||||
|
version = "0.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5255b9ff16ff898710eb9eb63cb39248ea8a5bb036bea8085b1a767ff6c4e3fc"
|
||||||
|
dependencies = [
|
||||||
|
"static_assertions",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lexical-write-float"
|
||||||
|
version = "0.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "accabaa1c4581f05a3923d1b4cfd124c329352288b7b9da09e766b0668116862"
|
||||||
|
dependencies = [
|
||||||
|
"lexical-util",
|
||||||
|
"lexical-write-integer",
|
||||||
|
"static_assertions",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lexical-write-integer"
|
||||||
|
version = "0.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e1b6f3d1f4422866b68192d62f77bc5c700bee84f3069f2469d7bc8c77852446"
|
||||||
|
dependencies = [
|
||||||
|
"lexical-util",
|
||||||
|
"static_assertions",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.144"
|
version = "0.2.144"
|
||||||
|
|
@ -2162,11 +2226,12 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "simd-json"
|
name = "simd-json"
|
||||||
version = "0.6.0"
|
version = "0.10.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9bd78b840b9de64fa3f7d72909b76343849f68e8c3d32608db8d38e4e5481f84"
|
checksum = "a3d0815e7ff0f1f05e09d4b029f86d8a330f0ab15b35b28736f3758325f59e14"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"halfbrown",
|
"halfbrown",
|
||||||
|
"lexical-core",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"simdutf8",
|
"simdutf8",
|
||||||
|
|
@ -2540,9 +2605,9 @@ checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "value-trait"
|
name = "value-trait"
|
||||||
version = "0.4.0"
|
version = "0.6.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c0a635407649b66e125e4d2ffd208153210179f8c7c8b71c030aa2ad3eeb4c8f"
|
checksum = "09a5b6c8ceb01263b969cac48d4a6705134d490ded13d889e52c0cfc80c6945e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"float-cmp",
|
"float-cmp",
|
||||||
"halfbrown",
|
"halfbrown",
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ serde = { version = "1", features = ["derive"] }
|
||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
# simd-json version 0.7 seems to have bugs in string parsing
|
# simd-json version 0.7 seems to have bugs in string parsing
|
||||||
# with custom visitor, where it includes quotes in strings
|
# with custom visitor, where it includes quotes in strings
|
||||||
simd-json = { version = "0.6", features = ["allow-non-simd"] }
|
simd-json = { version = "0.10", features = ["allow-non-simd"] }
|
||||||
tungstenite = "0.19"
|
tungstenite = "0.19"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
|
||||||
|
|
@ -202,39 +202,50 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_deserialize_20_bytes() {
|
fn test_deserialize_20_bytes() {
|
||||||
|
unsafe {
|
||||||
let mut input = r#""aaaabbbbccccddddeeee""#.to_string();
|
let mut input = r#""aaaabbbbccccddddeeee""#.to_string();
|
||||||
|
|
||||||
let expected = info_hash_from_bytes(b"aaaabbbbccccddddeeee");
|
let expected = info_hash_from_bytes(b"aaaabbbbccccddddeeee");
|
||||||
let observed: InfoHash = ::simd_json::serde::from_str(&mut input).unwrap();
|
let observed: InfoHash = ::simd_json::serde::from_str(&mut input).unwrap();
|
||||||
|
|
||||||
assert_eq!(observed, expected);
|
assert_eq!(observed, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe {
|
||||||
let mut input = r#""aaaabbbbccccddddeee""#.to_string();
|
let mut input = r#""aaaabbbbccccddddeee""#.to_string();
|
||||||
let res_info_hash: Result<InfoHash, _> = ::simd_json::serde::from_str(&mut input);
|
let res_info_hash: Result<InfoHash, _> = ::simd_json::serde::from_str(&mut input);
|
||||||
|
|
||||||
assert!(res_info_hash.is_err());
|
assert!(res_info_hash.is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe {
|
||||||
let mut input = r#""aaaabbbbccccddddeee𝕊""#.to_string();
|
let mut input = r#""aaaabbbbccccddddeee𝕊""#.to_string();
|
||||||
let res_info_hash: Result<InfoHash, _> = ::simd_json::serde::from_str(&mut input);
|
let res_info_hash: Result<InfoHash, _> = ::simd_json::serde::from_str(&mut input);
|
||||||
|
|
||||||
assert!(res_info_hash.is_err());
|
assert!(res_info_hash.is_err());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_serde_20_bytes() {
|
fn test_serde_20_bytes() {
|
||||||
let info_hash = info_hash_from_bytes(b"aaaabbbbccccddddeeee");
|
let info_hash = info_hash_from_bytes(b"aaaabbbbccccddddeeee");
|
||||||
|
|
||||||
|
let info_hash_2 = unsafe {
|
||||||
let mut out = ::simd_json::serde::to_string(&info_hash).unwrap();
|
let mut out = ::simd_json::serde::to_string(&info_hash).unwrap();
|
||||||
let info_hash_2 = ::simd_json::serde::from_str(&mut out).unwrap();
|
|
||||||
|
::simd_json::serde::from_str(&mut out).unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
assert_eq!(info_hash, info_hash_2);
|
assert_eq!(info_hash, info_hash_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[quickcheck]
|
#[quickcheck]
|
||||||
fn quickcheck_serde_20_bytes(info_hash: InfoHash) -> bool {
|
fn quickcheck_serde_20_bytes(info_hash: InfoHash) -> bool {
|
||||||
|
unsafe {
|
||||||
let mut out = ::simd_json::serde::to_string(&info_hash).unwrap();
|
let mut out = ::simd_json::serde::to_string(&info_hash).unwrap();
|
||||||
let info_hash_2 = ::simd_json::serde::from_str(&mut out).unwrap();
|
let info_hash_2 = ::simd_json::serde::from_str(&mut out).unwrap();
|
||||||
|
|
||||||
info_hash == info_hash_2
|
info_hash == info_hash_2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -262,12 +262,6 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_deserialize_info_hashes_vec() {
|
fn test_deserialize_info_hashes_vec() {
|
||||||
let mut input: String = r#"{
|
|
||||||
"action": "scrape",
|
|
||||||
"info_hash": ["aaaabbbbccccddddeeee", "aaaabbbbccccddddeeee"]
|
|
||||||
}"#
|
|
||||||
.into();
|
|
||||||
|
|
||||||
let info_hashes = ScrapeRequestInfoHashes::Multiple(vec![
|
let info_hashes = ScrapeRequestInfoHashes::Multiple(vec![
|
||||||
info_hash_from_bytes(b"aaaabbbbccccddddeeee"),
|
info_hash_from_bytes(b"aaaabbbbccccddddeeee"),
|
||||||
info_hash_from_bytes(b"aaaabbbbccccddddeeee"),
|
info_hash_from_bytes(b"aaaabbbbccccddddeeee"),
|
||||||
|
|
@ -278,19 +272,21 @@ mod tests {
|
||||||
info_hashes: Some(info_hashes),
|
info_hashes: Some(info_hashes),
|
||||||
};
|
};
|
||||||
|
|
||||||
let observed: ScrapeRequest = ::simd_json::serde::from_str(&mut input).unwrap();
|
let observed: ScrapeRequest = unsafe {
|
||||||
|
let mut input: String = r#"{
|
||||||
|
"action": "scrape",
|
||||||
|
"info_hash": ["aaaabbbbccccddddeeee", "aaaabbbbccccddddeeee"]
|
||||||
|
}"#
|
||||||
|
.into();
|
||||||
|
|
||||||
|
::simd_json::serde::from_str(&mut input).unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
assert_eq!(expected, observed);
|
assert_eq!(expected, observed);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_deserialize_info_hashes_str() {
|
fn test_deserialize_info_hashes_str() {
|
||||||
let mut input: String = r#"{
|
|
||||||
"action": "scrape",
|
|
||||||
"info_hash": "aaaabbbbccccddddeeee"
|
|
||||||
}"#
|
|
||||||
.into();
|
|
||||||
|
|
||||||
let info_hashes =
|
let info_hashes =
|
||||||
ScrapeRequestInfoHashes::Single(info_hash_from_bytes(b"aaaabbbbccccddddeeee"));
|
ScrapeRequestInfoHashes::Single(info_hash_from_bytes(b"aaaabbbbccccddddeeee"));
|
||||||
|
|
||||||
|
|
@ -299,54 +295,65 @@ mod tests {
|
||||||
info_hashes: Some(info_hashes),
|
info_hashes: Some(info_hashes),
|
||||||
};
|
};
|
||||||
|
|
||||||
let observed: ScrapeRequest = ::simd_json::serde::from_str(&mut input).unwrap();
|
let observed: ScrapeRequest = unsafe {
|
||||||
|
let mut input: String = r#"{
|
||||||
|
"action": "scrape",
|
||||||
|
"info_hash": "aaaabbbbccccddddeeee"
|
||||||
|
}"#
|
||||||
|
.into();
|
||||||
|
|
||||||
|
::simd_json::serde::from_str(&mut input).unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
assert_eq!(expected, observed);
|
assert_eq!(expected, observed);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_deserialize_info_hashes_null() {
|
fn test_deserialize_info_hashes_null() {
|
||||||
|
let observed: ScrapeRequest = unsafe {
|
||||||
let mut input: String = r#"{
|
let mut input: String = r#"{
|
||||||
"action": "scrape",
|
"action": "scrape",
|
||||||
"info_hash": null
|
"info_hash": null
|
||||||
}"#
|
}"#
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
|
::simd_json::serde::from_str(&mut input).unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
let expected = ScrapeRequest {
|
let expected = ScrapeRequest {
|
||||||
action: ScrapeAction,
|
action: ScrapeAction,
|
||||||
info_hashes: None,
|
info_hashes: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let observed: ScrapeRequest = ::simd_json::serde::from_str(&mut input).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(expected, observed);
|
assert_eq!(expected, observed);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_deserialize_info_hashes_missing() {
|
fn test_deserialize_info_hashes_missing() {
|
||||||
|
let observed: ScrapeRequest = unsafe {
|
||||||
let mut input: String = r#"{
|
let mut input: String = r#"{
|
||||||
"action": "scrape"
|
"action": "scrape"
|
||||||
}"#
|
}"#
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
|
::simd_json::serde::from_str(&mut input).unwrap()
|
||||||
|
};
|
||||||
|
|
||||||
let expected = ScrapeRequest {
|
let expected = ScrapeRequest {
|
||||||
action: ScrapeAction,
|
action: ScrapeAction,
|
||||||
info_hashes: None,
|
info_hashes: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let observed: ScrapeRequest = ::simd_json::serde::from_str(&mut input).unwrap();
|
|
||||||
|
|
||||||
assert_eq!(expected, observed);
|
assert_eq!(expected, observed);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[quickcheck]
|
#[quickcheck]
|
||||||
fn quickcheck_serde_identity_info_hashes(info_hashes: ScrapeRequestInfoHashes) -> bool {
|
fn quickcheck_serde_identity_info_hashes(info_hashes: ScrapeRequestInfoHashes) -> bool {
|
||||||
|
let deserialized: ScrapeRequestInfoHashes = unsafe {
|
||||||
let mut json = ::simd_json::serde::to_string(&info_hashes).unwrap();
|
let mut json = ::simd_json::serde::to_string(&info_hashes).unwrap();
|
||||||
|
|
||||||
println!("{}", json);
|
::simd_json::serde::from_str(&mut json).unwrap()
|
||||||
|
};
|
||||||
let deserialized: ScrapeRequestInfoHashes =
|
|
||||||
::simd_json::serde::from_str(&mut json).unwrap();
|
|
||||||
|
|
||||||
let success = info_hashes == deserialized;
|
let success = info_hashes == deserialized;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,10 @@ impl InMessage {
|
||||||
use tungstenite::Message;
|
use tungstenite::Message;
|
||||||
|
|
||||||
match ws_message {
|
match ws_message {
|
||||||
Message::Text(mut text) => {
|
Message::Text(text) => {
|
||||||
::simd_json::serde::from_str(&mut text).context("deserialize with serde")
|
let mut text: Vec<u8> = text.into();
|
||||||
|
|
||||||
|
::simd_json::serde::from_slice(&mut text).context("deserialize with serde")
|
||||||
}
|
}
|
||||||
Message::Binary(mut bytes) => {
|
Message::Binary(mut bytes) => {
|
||||||
::simd_json::serde::from_slice(&mut bytes[..]).context("deserialize with serde")
|
::simd_json::serde::from_slice(&mut bytes[..]).context("deserialize with serde")
|
||||||
|
|
|
||||||
|
|
@ -33,12 +33,12 @@ impl OutMessage {
|
||||||
pub fn from_ws_message(message: ::tungstenite::Message) -> ::anyhow::Result<Self> {
|
pub fn from_ws_message(message: ::tungstenite::Message) -> ::anyhow::Result<Self> {
|
||||||
use tungstenite::Message::{Binary, Text};
|
use tungstenite::Message::{Binary, Text};
|
||||||
|
|
||||||
let mut text = match message {
|
let mut text: Vec<u8> = match message {
|
||||||
Text(text) => text,
|
Text(text) => text.into(),
|
||||||
Binary(bytes) => String::from_utf8(bytes)?,
|
Binary(bytes) => String::from_utf8(bytes)?.into(),
|
||||||
_ => return Err(anyhow::anyhow!("Message is neither text nor bytes")),
|
_ => return Err(anyhow::anyhow!("Message is neither text nor bytes")),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(::simd_json::serde::from_str(&mut text)?)
|
Ok(::simd_json::serde::from_slice(&mut text)?)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue