mirror of
https://github.com/cccb/servicepoint.git
synced 2025-01-18 10:00:14 +01:00
add lzma as only default compression, add missing cfg annotations
This commit is contained in:
parent
e615f3f949
commit
79e963d045
|
@ -26,7 +26,7 @@ fn main() {
|
||||||
Command::BitmapLinearWin(
|
Command::BitmapLinearWin(
|
||||||
Origin(0, 0),
|
Origin(0, 0),
|
||||||
field.clone(),
|
field.clone(),
|
||||||
CompressionCode::Bzip2,
|
CompressionCode::Lzma,
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -20,10 +20,9 @@ zstd = { version = "0.13", optional = true }
|
||||||
rust-lzma = { version = "0.6.0", optional = true }
|
rust-lzma = { version = "0.6.0", optional = true }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["compression_zlib", "compression_bzip2", "compression_lzma", "compression_zstd"]
|
default = ["compression_lzma"]
|
||||||
compression_zlib = ["dep:flate2", "compression"]
|
compression_zlib = ["dep:flate2"]
|
||||||
compression_bzip2 = ["dep:bzip2", "compression"]
|
compression_bzip2 = ["dep:bzip2"]
|
||||||
compression_lzma = ["dep:rust-lzma", "compression"]
|
compression_lzma = ["dep:rust-lzma"]
|
||||||
compression_zstd = ["dep:zstd", "compression"]
|
compression_zstd = ["dep:zstd"]
|
||||||
compression = []
|
|
||||||
c_api = []
|
c_api = []
|
||||||
|
|
|
@ -104,9 +104,13 @@ impl From<Command> for Packet {
|
||||||
CompressionCode::Uncompressed => {
|
CompressionCode::Uncompressed => {
|
||||||
CommandCode::BitmapLinearWinUncompressed
|
CommandCode::BitmapLinearWinUncompressed
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "compression_zlib")]
|
||||||
CompressionCode::Zlib => CommandCode::BitmapLinearWinZlib,
|
CompressionCode::Zlib => CommandCode::BitmapLinearWinZlib,
|
||||||
|
#[cfg(feature = "compression_bzip2")]
|
||||||
CompressionCode::Bzip2 => CommandCode::BitmapLinearWinBzip2,
|
CompressionCode::Bzip2 => CommandCode::BitmapLinearWinBzip2,
|
||||||
|
#[cfg(feature = "compression_lzma")]
|
||||||
CompressionCode::Lzma => CommandCode::BitmapLinearWinLzma,
|
CompressionCode::Lzma => CommandCode::BitmapLinearWinLzma,
|
||||||
|
#[cfg(feature = "compression_zstd")]
|
||||||
CompressionCode::Zstd => CommandCode::BitmapLinearWinZstd,
|
CompressionCode::Zstd => CommandCode::BitmapLinearWinZstd,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -263,15 +267,19 @@ impl TryFrom<Packet> for Command {
|
||||||
CompressionCode::Uncompressed,
|
CompressionCode::Uncompressed,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "compression_zlib")]
|
||||||
CommandCode::BitmapLinearWinZlib => {
|
CommandCode::BitmapLinearWinZlib => {
|
||||||
Self::packet_into_bitmap_win(packet, CompressionCode::Zlib)
|
Self::packet_into_bitmap_win(packet, CompressionCode::Zlib)
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "compression_bzip2")]
|
||||||
CommandCode::BitmapLinearWinBzip2 => {
|
CommandCode::BitmapLinearWinBzip2 => {
|
||||||
Self::packet_into_bitmap_win(packet, CompressionCode::Bzip2)
|
Self::packet_into_bitmap_win(packet, CompressionCode::Bzip2)
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "compression_lzma")]
|
||||||
CommandCode::BitmapLinearWinLzma => {
|
CommandCode::BitmapLinearWinLzma => {
|
||||||
Self::packet_into_bitmap_win(packet, CompressionCode::Lzma)
|
Self::packet_into_bitmap_win(packet, CompressionCode::Lzma)
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "compression_zstd")]
|
||||||
CommandCode::BitmapLinearWinZstd => {
|
CommandCode::BitmapLinearWinZstd => {
|
||||||
Self::packet_into_bitmap_win(packet, CompressionCode::Zstd)
|
Self::packet_into_bitmap_win(packet, CompressionCode::Zstd)
|
||||||
}
|
}
|
||||||
|
@ -541,8 +549,8 @@ mod tests {
|
||||||
use crate::command::TryFromPacketError;
|
use crate::command::TryFromPacketError;
|
||||||
use crate::command_code::CommandCode;
|
use crate::command_code::CommandCode;
|
||||||
use crate::{
|
use crate::{
|
||||||
BitVec, ByteGrid, Command, CompressionCode, Header, Origin, Packet,
|
BitVec, ByteGrid, Command, CompressionCode, Grid, Header, Origin,
|
||||||
PixelGrid,
|
Packet, PixelGrid,
|
||||||
};
|
};
|
||||||
|
|
||||||
fn round_trip(original: Command) {
|
fn round_trip(original: Command) {
|
||||||
|
@ -554,12 +562,16 @@ mod tests {
|
||||||
assert_eq!(copy, original);
|
assert_eq!(copy, original);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn all_compressions() -> [CompressionCode; 5] {
|
fn all_compressions<'t>() -> &'t [CompressionCode] {
|
||||||
[
|
&[
|
||||||
CompressionCode::Uncompressed,
|
CompressionCode::Uncompressed,
|
||||||
|
#[cfg(feature = "compression_lzma")]
|
||||||
CompressionCode::Lzma,
|
CompressionCode::Lzma,
|
||||||
|
#[cfg(feature = "compression_bzip2")]
|
||||||
CompressionCode::Bzip2,
|
CompressionCode::Bzip2,
|
||||||
|
#[cfg(feature = "compression_zlib")]
|
||||||
CompressionCode::Zlib,
|
CompressionCode::Zlib,
|
||||||
|
#[cfg(feature = "compression_zstd")]
|
||||||
CompressionCode::Zstd,
|
CompressionCode::Zstd,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -602,7 +614,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn round_trip_bitmap_linear() {
|
fn round_trip_bitmap_linear() {
|
||||||
for compression in all_compressions() {
|
for compression in all_compressions().to_owned() {
|
||||||
round_trip(Command::BitmapLinear(23, BitVec::new(40), compression));
|
round_trip(Command::BitmapLinear(23, BitVec::new(40), compression));
|
||||||
round_trip(Command::BitmapLinearAnd(
|
round_trip(Command::BitmapLinearAnd(
|
||||||
23,
|
23,
|
||||||
|
@ -704,7 +716,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_decompression_failed_win() {
|
fn error_decompression_failed_win() {
|
||||||
for compression in all_compressions() {
|
for compression in all_compressions().to_owned() {
|
||||||
let p: Packet = Command::BitmapLinearWin(
|
let p: Packet = Command::BitmapLinearWin(
|
||||||
Origin(16, 8),
|
Origin(16, 8),
|
||||||
PixelGrid::new(8, 8),
|
PixelGrid::new(8, 8),
|
||||||
|
@ -730,7 +742,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn error_decompression_failed_and() {
|
fn error_decompression_failed_and() {
|
||||||
for compression in all_compressions() {
|
for compression in all_compressions().to_owned() {
|
||||||
let p: Packet =
|
let p: Packet =
|
||||||
Command::BitmapLinearAnd(0, BitVec::new(8), compression).into();
|
Command::BitmapLinearAnd(0, BitVec::new(8), compression).into();
|
||||||
let Packet(header, mut payload) = p;
|
let Packet(header, mut payload) = p;
|
||||||
|
|
|
@ -15,9 +15,13 @@ pub(crate) enum CommandCode {
|
||||||
BitmapLinearAnd = 0x0014,
|
BitmapLinearAnd = 0x0014,
|
||||||
BitmapLinearOr = 0x0015,
|
BitmapLinearOr = 0x0015,
|
||||||
BitmapLinearXor = 0x0016,
|
BitmapLinearXor = 0x0016,
|
||||||
|
#[cfg(feature = "compression_zlib")]
|
||||||
BitmapLinearWinZlib = 0x0017,
|
BitmapLinearWinZlib = 0x0017,
|
||||||
|
#[cfg(feature = "compression_bzip2")]
|
||||||
BitmapLinearWinBzip2 = 0x0018,
|
BitmapLinearWinBzip2 = 0x0018,
|
||||||
|
#[cfg(feature = "compression_lzma")]
|
||||||
BitmapLinearWinLzma = 0x0019,
|
BitmapLinearWinLzma = 0x0019,
|
||||||
|
#[cfg(feature = "compression_zstd")]
|
||||||
BitmapLinearWinZstd = 0x001A,
|
BitmapLinearWinZstd = 0x001A,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,15 +55,19 @@ impl TryFrom<u16> for CommandCode {
|
||||||
value if value == BitmapLinearAnd as u16 => Ok(BitmapLinearAnd),
|
value if value == BitmapLinearAnd as u16 => Ok(BitmapLinearAnd),
|
||||||
value if value == BitmapLinearOr as u16 => Ok(BitmapLinearOr),
|
value if value == BitmapLinearOr as u16 => Ok(BitmapLinearOr),
|
||||||
value if value == BitmapLinearXor as u16 => Ok(BitmapLinearXor),
|
value if value == BitmapLinearXor as u16 => Ok(BitmapLinearXor),
|
||||||
|
#[cfg(feature = "compression_zstd")]
|
||||||
value if value == BitmapLinearWinZstd as u16 => {
|
value if value == BitmapLinearWinZstd as u16 => {
|
||||||
Ok(BitmapLinearWinZstd)
|
Ok(BitmapLinearWinZstd)
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "compression_lzma")]
|
||||||
value if value == BitmapLinearWinLzma as u16 => {
|
value if value == BitmapLinearWinLzma as u16 => {
|
||||||
Ok(BitmapLinearWinLzma)
|
Ok(BitmapLinearWinLzma)
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "compression_zlib")]
|
||||||
value if value == BitmapLinearWinZlib as u16 => {
|
value if value == BitmapLinearWinZlib as u16 => {
|
||||||
Ok(BitmapLinearWinZlib)
|
Ok(BitmapLinearWinZlib)
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "compression_bzip2")]
|
||||||
value if value == BitmapLinearWinBzip2 as u16 => {
|
value if value == BitmapLinearWinBzip2 as u16 => {
|
||||||
Ok(BitmapLinearWinBzip2)
|
Ok(BitmapLinearWinBzip2)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#[cfg(feature = "compression")]
|
#[allow(unused)]
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
#[cfg(feature = "compression_bzip2")]
|
#[cfg(feature = "compression_bzip2")]
|
||||||
|
|
Loading…
Reference in a new issue