-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(engine): add zstd compression support for geometry attributes
- Loading branch information
Showing
9 changed files
with
93 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,3 +162,4 @@ uuid = { version = "1.10.0", features = [ | |
"serde", | ||
"v4", | ||
] } | ||
zstd = "0.13.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use crate::{ | ||
str::{base64_decode_byte, base64_encode}, | ||
Error, Result, | ||
}; | ||
|
||
pub fn compress(source: &str) -> Result<String> { | ||
let compressed = zstd::encode_all(source.as_bytes(), 3) | ||
.map_err(|e| Error::Compress(format!("Failed to compress: {}", e)))?; | ||
Ok(base64_encode(&compressed)) | ||
} | ||
|
||
pub fn decode(source: String) -> Result<String> { | ||
let bytes = base64_decode_byte(source)?; | ||
let decoded = zstd::decode_all(bytes.as_slice()) | ||
.map_err(|e| Error::Compress(format!("Failed to decompress: {}", e)))?; | ||
Ok(String::from_utf8_lossy(&decoded).to_string()) | ||
} | ||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_compress_and_decode() { | ||
let original = "This is a test string to compress and decompress."; | ||
let compressed = compress(original).expect("Compression failed"); | ||
let decompressed = decode(compressed).expect("Decompression failed"); | ||
assert_eq!(original, decompressed); | ||
} | ||
|
||
#[test] | ||
fn test_compress_empty_string() { | ||
let original = ""; | ||
let compressed = compress(original).expect("Compression failed"); | ||
let decompressed = decode(compressed).expect("Decompression failed"); | ||
assert_eq!(original, decompressed); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters