From 03aa432655dc6230679e30621fb04004d190d49d Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Mon, 4 Nov 2024 22:21:28 +0100 Subject: [PATCH] add uniffi compression code, clone add uniffi clone --- .../servicepoint_binding_uniffi.cs | 170 +++++++++++++++--- .../servicepoint_binding_uniffi/src/bitmap.rs | 5 + .../servicepoint_binding_uniffi/src/bitvec.rs | 5 + .../src/brightness_grid.rs | 5 + .../src/command.rs | 53 ++++-- .../src/compression_code.rs | 14 ++ crates/servicepoint_binding_uniffi/src/lib.rs | 1 + 7 files changed, 213 insertions(+), 40 deletions(-) create mode 100644 crates/servicepoint_binding_uniffi/src/compression_code.rs diff --git a/crates/servicepoint_binding_uniffi/libraries/csharp/ServicePoint/servicepoint_binding_uniffi.cs b/crates/servicepoint_binding_uniffi/libraries/csharp/ServicePoint/servicepoint_binding_uniffi.cs index a35e75f..cd0eda5 100644 --- a/crates/servicepoint_binding_uniffi/libraries/csharp/ServicePoint/servicepoint_binding_uniffi.cs +++ b/crates/servicepoint_binding_uniffi/libraries/csharp/ServicePoint/servicepoint_binding_uniffi.cs @@ -433,6 +433,10 @@ static class _UniFFILib { IntPtr ptr,ref RustCallStatus _uniffi_out_err ); + [DllImport("servicepoint_binding_uniffi")] + public static extern BitVecSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_bitvec_clone(BitVecSafeHandle @other,ref RustCallStatus _uniffi_out_err + ); + [DllImport("servicepoint_binding_uniffi")] public static extern BitVecSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_bitvec_load(RustBuffer @data,ref RustCallStatus _uniffi_out_err ); @@ -462,6 +466,10 @@ static class _UniFFILib { IntPtr ptr,ref RustCallStatus _uniffi_out_err ); + [DllImport("servicepoint_binding_uniffi")] + public static extern BitmapSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_bitmap_clone(BitmapSafeHandle @other,ref RustCallStatus _uniffi_out_err + ); + [DllImport("servicepoint_binding_uniffi")] public static extern BitmapSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_bitmap_load(ulong @width,ulong @height,RustBuffer @data,ref RustCallStatus _uniffi_out_err ); @@ -499,6 +507,10 @@ static class _UniFFILib { IntPtr ptr,ref RustCallStatus _uniffi_out_err ); + [DllImport("servicepoint_binding_uniffi")] + public static extern BrightnessGridSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_brightnessgrid_clone(BrightnessGridSafeHandle @other,ref RustCallStatus _uniffi_out_err + ); + [DllImport("servicepoint_binding_uniffi")] public static extern BrightnessGridSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_brightnessgrid_load(ulong @width,ulong @height,RustBuffer @data,ref RustCallStatus _uniffi_out_err ); @@ -533,23 +545,23 @@ static class _UniFFILib { ); [DllImport("servicepoint_binding_uniffi")] - public static extern CommandSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_command_bitmap_linear(ulong @offset,BitVecSafeHandle @bitmap,ref RustCallStatus _uniffi_out_err + public static extern CommandSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_command_bitmap_linear(ulong @offset,BitVecSafeHandle @bitmap,RustBuffer @compression,ref RustCallStatus _uniffi_out_err ); [DllImport("servicepoint_binding_uniffi")] - public static extern CommandSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_command_bitmap_linear_and(ulong @offset,BitVecSafeHandle @bitmap,ref RustCallStatus _uniffi_out_err + public static extern CommandSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_command_bitmap_linear_and(ulong @offset,BitVecSafeHandle @bitmap,RustBuffer @compression,ref RustCallStatus _uniffi_out_err ); [DllImport("servicepoint_binding_uniffi")] - public static extern CommandSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_command_bitmap_linear_or(ulong @offset,BitVecSafeHandle @bitmap,ref RustCallStatus _uniffi_out_err + public static extern CommandSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_command_bitmap_linear_or(ulong @offset,BitVecSafeHandle @bitmap,RustBuffer @compression,ref RustCallStatus _uniffi_out_err ); [DllImport("servicepoint_binding_uniffi")] - public static extern CommandSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_command_bitmap_linear_win(ulong @offsetX,ulong @offsetY,BitmapSafeHandle @bitmap,ref RustCallStatus _uniffi_out_err + public static extern CommandSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_command_bitmap_linear_win(ulong @offsetX,ulong @offsetY,BitmapSafeHandle @bitmap,RustBuffer @compression,ref RustCallStatus _uniffi_out_err ); [DllImport("servicepoint_binding_uniffi")] - public static extern CommandSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_command_bitmap_linear_xor(ulong @offset,BitVecSafeHandle @bitmap,ref RustCallStatus _uniffi_out_err + public static extern CommandSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_command_bitmap_linear_xor(ulong @offset,BitVecSafeHandle @bitmap,RustBuffer @compression,ref RustCallStatus _uniffi_out_err ); [DllImport("servicepoint_binding_uniffi")] @@ -564,6 +576,10 @@ static class _UniFFILib { public static extern CommandSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_command_clear(ref RustCallStatus _uniffi_out_err ); + [DllImport("servicepoint_binding_uniffi")] + public static extern CommandSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_command_clone(CommandSafeHandle @other,ref RustCallStatus _uniffi_out_err + ); + [DllImport("servicepoint_binding_uniffi")] public static extern CommandSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_command_fade_out(ref RustCallStatus _uniffi_out_err ); @@ -877,6 +893,10 @@ static class _UniFFILib { public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_method_connection_send( ); + [DllImport("servicepoint_binding_uniffi")] + public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_constructor_bitvec_clone( + ); + [DllImport("servicepoint_binding_uniffi")] public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_constructor_bitvec_load( ); @@ -885,6 +905,10 @@ static class _UniFFILib { public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_constructor_bitvec_new( ); + [DllImport("servicepoint_binding_uniffi")] + public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_constructor_bitmap_clone( + ); + [DllImport("servicepoint_binding_uniffi")] public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_constructor_bitmap_load( ); @@ -897,6 +921,10 @@ static class _UniFFILib { public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_constructor_bitmap_new_max_sized( ); + [DllImport("servicepoint_binding_uniffi")] + public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_constructor_brightnessgrid_clone( + ); + [DllImport("servicepoint_binding_uniffi")] public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_constructor_brightnessgrid_load( ); @@ -937,6 +965,10 @@ static class _UniFFILib { public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_constructor_command_clear( ); + [DllImport("servicepoint_binding_uniffi")] + public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_constructor_command_clone( + ); + [DllImport("servicepoint_binding_uniffi")] public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_constructor_command_fade_out( ); @@ -1057,6 +1089,12 @@ static class _UniFFILib { throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_method_connection_send` checksum `23796`, library returned `{checksum}`"); } } + { + var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_constructor_bitvec_clone(); + if (checksum != 123) { + throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_bitvec_clone` checksum `123`, library returned `{checksum}`"); + } + } { var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_constructor_bitvec_load(); if (checksum != 48913) { @@ -1069,6 +1107,12 @@ static class _UniFFILib { throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_bitvec_new` checksum `11865`, library returned `{checksum}`"); } } + { + var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_constructor_bitmap_clone(); + if (checksum != 57298) { + throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_bitmap_clone` checksum `57298`, library returned `{checksum}`"); + } + } { var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_constructor_bitmap_load(); if (checksum != 24109) { @@ -1087,6 +1131,12 @@ static class _UniFFILib { throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_bitmap_new_max_sized` checksum `63762`, library returned `{checksum}`"); } } + { + var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_constructor_brightnessgrid_clone(); + if (checksum != 33422) { + throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_brightnessgrid_clone` checksum `33422`, library returned `{checksum}`"); + } + } { var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_constructor_brightnessgrid_load(); if (checksum != 24788) { @@ -1101,32 +1151,32 @@ static class _UniFFILib { } { var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_constructor_command_bitmap_linear(); - if (checksum != 14881) { - throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_command_bitmap_linear` checksum `14881`, library returned `{checksum}`"); + if (checksum != 18079) { + throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_command_bitmap_linear` checksum `18079`, library returned `{checksum}`"); } } { var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_constructor_command_bitmap_linear_and(); - if (checksum != 7352) { - throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_command_bitmap_linear_and` checksum `7352`, library returned `{checksum}`"); + if (checksum != 18147) { + throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_command_bitmap_linear_and` checksum `18147`, library returned `{checksum}`"); } } { var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_constructor_command_bitmap_linear_or(); - if (checksum != 7046) { - throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_command_bitmap_linear_or` checksum `7046`, library returned `{checksum}`"); + if (checksum != 44912) { + throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_command_bitmap_linear_or` checksum `44912`, library returned `{checksum}`"); } } { var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_constructor_command_bitmap_linear_win(); - if (checksum != 51700) { - throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_command_bitmap_linear_win` checksum `51700`, library returned `{checksum}`"); + if (checksum != 24563) { + throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_command_bitmap_linear_win` checksum `24563`, library returned `{checksum}`"); } } { var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_constructor_command_bitmap_linear_xor(); - if (checksum != 54209) { - throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_command_bitmap_linear_xor` checksum `54209`, library returned `{checksum}`"); + if (checksum != 54278) { + throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_command_bitmap_linear_xor` checksum `54278`, library returned `{checksum}`"); } } { @@ -1147,6 +1197,12 @@ static class _UniFFILib { throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_command_clear` checksum `11035`, library returned `{checksum}`"); } } + { + var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_constructor_command_clone(); + if (checksum != 42249) { + throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_command_clone` checksum `42249`, library returned `{checksum}`"); + } + } { var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_constructor_command_fade_out(); if (checksum != 49231) { @@ -1475,6 +1531,13 @@ public class BitVec: FFIObject, IBitVec { + public static BitVec Clone(BitVec @other) { + return new BitVec( + _UniffiHelpers.RustCall( (ref RustCallStatus _status) => + _UniFFILib.uniffi_servicepoint_binding_uniffi_fn_constructor_bitvec_clone(FfiConverterTypeBitVec.INSTANCE.Lower(@other), ref _status) +)); + } + public static BitVec Load(byte[] @data) { return new BitVec( _UniffiHelpers.RustCall( (ref RustCallStatus _status) => @@ -1583,6 +1646,13 @@ public class Bitmap: FFIObject, IBitmap { + public static Bitmap Clone(Bitmap @other) { + return new Bitmap( + _UniffiHelpers.RustCall( (ref RustCallStatus _status) => + _UniFFILib.uniffi_servicepoint_binding_uniffi_fn_constructor_bitmap_clone(FfiConverterTypeBitmap.INSTANCE.Lower(@other), ref _status) +)); + } + public static Bitmap Load(ulong @width, ulong @height, byte[] @data) { return new Bitmap( _UniffiHelpers.RustCall( (ref RustCallStatus _status) => @@ -1698,6 +1768,13 @@ public class BrightnessGrid: FFIObject, IBrightnessGri + public static BrightnessGrid Clone(BrightnessGrid @other) { + return new BrightnessGrid( + _UniffiHelpers.RustCall( (ref RustCallStatus _status) => + _UniFFILib.uniffi_servicepoint_binding_uniffi_fn_constructor_brightnessgrid_clone(FfiConverterTypeBrightnessGrid.INSTANCE.Lower(@other), ref _status) +)); + } + public static BrightnessGrid Load(ulong @width, ulong @height, byte[] @data) { return new BrightnessGrid( _UniffiHelpers.RustCall( (ref RustCallStatus _status) => @@ -1756,38 +1833,38 @@ public class Command: FFIObject, ICommand { - public static Command BitmapLinear(ulong @offset, BitVec @bitmap) { + public static Command BitmapLinear(ulong @offset, BitVec @bitmap, CompressionCode @compression) { return new Command( _UniffiHelpers.RustCall( (ref RustCallStatus _status) => - _UniFFILib.uniffi_servicepoint_binding_uniffi_fn_constructor_command_bitmap_linear(FfiConverterUInt64.INSTANCE.Lower(@offset), FfiConverterTypeBitVec.INSTANCE.Lower(@bitmap), ref _status) + _UniFFILib.uniffi_servicepoint_binding_uniffi_fn_constructor_command_bitmap_linear(FfiConverterUInt64.INSTANCE.Lower(@offset), FfiConverterTypeBitVec.INSTANCE.Lower(@bitmap), FfiConverterTypeCompressionCode.INSTANCE.Lower(@compression), ref _status) )); } - public static Command BitmapLinearAnd(ulong @offset, BitVec @bitmap) { + public static Command BitmapLinearAnd(ulong @offset, BitVec @bitmap, CompressionCode @compression) { return new Command( _UniffiHelpers.RustCall( (ref RustCallStatus _status) => - _UniFFILib.uniffi_servicepoint_binding_uniffi_fn_constructor_command_bitmap_linear_and(FfiConverterUInt64.INSTANCE.Lower(@offset), FfiConverterTypeBitVec.INSTANCE.Lower(@bitmap), ref _status) + _UniFFILib.uniffi_servicepoint_binding_uniffi_fn_constructor_command_bitmap_linear_and(FfiConverterUInt64.INSTANCE.Lower(@offset), FfiConverterTypeBitVec.INSTANCE.Lower(@bitmap), FfiConverterTypeCompressionCode.INSTANCE.Lower(@compression), ref _status) )); } - public static Command BitmapLinearOr(ulong @offset, BitVec @bitmap) { + public static Command BitmapLinearOr(ulong @offset, BitVec @bitmap, CompressionCode @compression) { return new Command( _UniffiHelpers.RustCall( (ref RustCallStatus _status) => - _UniFFILib.uniffi_servicepoint_binding_uniffi_fn_constructor_command_bitmap_linear_or(FfiConverterUInt64.INSTANCE.Lower(@offset), FfiConverterTypeBitVec.INSTANCE.Lower(@bitmap), ref _status) + _UniFFILib.uniffi_servicepoint_binding_uniffi_fn_constructor_command_bitmap_linear_or(FfiConverterUInt64.INSTANCE.Lower(@offset), FfiConverterTypeBitVec.INSTANCE.Lower(@bitmap), FfiConverterTypeCompressionCode.INSTANCE.Lower(@compression), ref _status) )); } - public static Command BitmapLinearWin(ulong @offsetX, ulong @offsetY, Bitmap @bitmap) { + public static Command BitmapLinearWin(ulong @offsetX, ulong @offsetY, Bitmap @bitmap, CompressionCode @compression) { return new Command( _UniffiHelpers.RustCall( (ref RustCallStatus _status) => - _UniFFILib.uniffi_servicepoint_binding_uniffi_fn_constructor_command_bitmap_linear_win(FfiConverterUInt64.INSTANCE.Lower(@offsetX), FfiConverterUInt64.INSTANCE.Lower(@offsetY), FfiConverterTypeBitmap.INSTANCE.Lower(@bitmap), ref _status) + _UniFFILib.uniffi_servicepoint_binding_uniffi_fn_constructor_command_bitmap_linear_win(FfiConverterUInt64.INSTANCE.Lower(@offsetX), FfiConverterUInt64.INSTANCE.Lower(@offsetY), FfiConverterTypeBitmap.INSTANCE.Lower(@bitmap), FfiConverterTypeCompressionCode.INSTANCE.Lower(@compression), ref _status) )); } - public static Command BitmapLinearXor(ulong @offset, BitVec @bitmap) { + public static Command BitmapLinearXor(ulong @offset, BitVec @bitmap, CompressionCode @compression) { return new Command( _UniffiHelpers.RustCall( (ref RustCallStatus _status) => - _UniFFILib.uniffi_servicepoint_binding_uniffi_fn_constructor_command_bitmap_linear_xor(FfiConverterUInt64.INSTANCE.Lower(@offset), FfiConverterTypeBitVec.INSTANCE.Lower(@bitmap), ref _status) + _UniFFILib.uniffi_servicepoint_binding_uniffi_fn_constructor_command_bitmap_linear_xor(FfiConverterUInt64.INSTANCE.Lower(@offset), FfiConverterTypeBitVec.INSTANCE.Lower(@bitmap), FfiConverterTypeCompressionCode.INSTANCE.Lower(@compression), ref _status) )); } @@ -1813,6 +1890,13 @@ public class Command: FFIObject, ICommand { )); } + public static Command Clone(Command @other) { + return new Command( + _UniffiHelpers.RustCall( (ref RustCallStatus _status) => + _UniFFILib.uniffi_servicepoint_binding_uniffi_fn_constructor_command_clone(FfiConverterTypeCommand.INSTANCE.Lower(@other), ref _status) +)); + } + public static Command FadeOut() { return new Command( _UniffiHelpers.RustCall( (ref RustCallStatus _status) => @@ -1932,6 +2016,42 @@ class FfiConverterTypeConnection: FfiConverter +public enum CompressionCode: int { + + Uncompressed, + Zlib, + Bzip2, + Lzma, + Zstd +} + +class FfiConverterTypeCompressionCode: FfiConverterRustBuffer { + public static FfiConverterTypeCompressionCode INSTANCE = new FfiConverterTypeCompressionCode(); + + public override CompressionCode Read(BigEndianStream stream) { + var value = stream.ReadInt() - 1; + if (Enum.IsDefined(typeof(CompressionCode), value)) { + return (CompressionCode)value; + } else { + throw new InternalException(String.Format("invalid enum value '{0}' in FfiConverterTypeCompressionCode.Read()", value)); + } + } + + public override int AllocationSize(CompressionCode value) { + return 4; + } + + public override void Write(CompressionCode value, BigEndianStream stream) { + stream.WriteInt((int)value + 1); + } +} + + + + + + + public class ServicePointException: UniffiException { // Each variant is a nested class diff --git a/crates/servicepoint_binding_uniffi/src/bitmap.rs b/crates/servicepoint_binding_uniffi/src/bitmap.rs index e0ebea4..881d628 100644 --- a/crates/servicepoint_binding_uniffi/src/bitmap.rs +++ b/crates/servicepoint_binding_uniffi/src/bitmap.rs @@ -38,6 +38,11 @@ impl Bitmap { )) } + #[uniffi::constructor] + pub fn clone(other: &Arc) -> Arc { + Self::internal_new(other.actual.read().unwrap().clone()) + } + pub fn set(&self, x: u64, y: u64, value: bool) { self.actual .write() diff --git a/crates/servicepoint_binding_uniffi/src/bitvec.rs b/crates/servicepoint_binding_uniffi/src/bitvec.rs index f495958..53c9bf4 100644 --- a/crates/servicepoint_binding_uniffi/src/bitvec.rs +++ b/crates/servicepoint_binding_uniffi/src/bitvec.rs @@ -24,6 +24,11 @@ impl BitVec { Self::internal_new(servicepoint::BitVec::from_slice(&data)) } + #[uniffi::constructor] + pub fn clone(other: &Arc) -> Arc { + Self::internal_new(other.actual.read().unwrap().clone()) + } + pub fn set(&self, index: u64, value: bool) { self.actual.write().unwrap().set(index as usize, value) } diff --git a/crates/servicepoint_binding_uniffi/src/brightness_grid.rs b/crates/servicepoint_binding_uniffi/src/brightness_grid.rs index ee97c53..c6562bc 100644 --- a/crates/servicepoint_binding_uniffi/src/brightness_grid.rs +++ b/crates/servicepoint_binding_uniffi/src/brightness_grid.rs @@ -33,6 +33,11 @@ impl BrightnessGrid { )) } + #[uniffi::constructor] + pub fn clone(other: &Arc) -> Arc { + Self::internal_new(other.actual.read().unwrap().clone()) + } + pub fn set(&self, x: u64, y: u64, value: u8) { self.actual.write().unwrap().set( x as usize, diff --git a/crates/servicepoint_binding_uniffi/src/command.rs b/crates/servicepoint_binding_uniffi/src/command.rs index 1cd3b7d..be2bbcc 100644 --- a/crates/servicepoint_binding_uniffi/src/command.rs +++ b/crates/servicepoint_binding_uniffi/src/command.rs @@ -1,8 +1,9 @@ use crate::bitmap::Bitmap; use crate::bitvec::BitVec; use crate::brightness_grid::BrightnessGrid; +use crate::compression_code::CompressionCode; use crate::errors::ServicePointError; -use servicepoint::{CompressionCode, Origin}; +use servicepoint::Origin; use std::sync::Arc; #[derive(uniffi::Object)] @@ -48,14 +49,15 @@ impl Command { offset_x: u64, offset_y: u64, bitmap: &Arc, + compression: CompressionCode, ) -> Arc { let origin = Origin::new(offset_x as usize, offset_y as usize); let bitmap = bitmap.actual.read().unwrap().clone(); - // TODO: compression codes let actual = servicepoint::Command::BitmapLinearWin( origin, bitmap, - CompressionCode::Uncompressed, + servicepoint::CompressionCode::try_from(compression as u16) + .unwrap(), ); Self::internal_new(actual) } @@ -73,50 +75,71 @@ impl Command { } #[uniffi::constructor] - pub fn bitmap_linear(offset: u64, bitmap: &Arc) -> Arc { + pub fn bitmap_linear( + offset: u64, + bitmap: &Arc, + compression: CompressionCode, + ) -> Arc { let bitmap = bitmap.actual.read().unwrap().clone(); - // TODO: compression codes let actual = servicepoint::Command::BitmapLinear( offset as usize, bitmap, - CompressionCode::Uncompressed, + servicepoint::CompressionCode::try_from(compression as u16) + .unwrap(), ); Self::internal_new(actual) } #[uniffi::constructor] - pub fn bitmap_linear_and(offset: u64, bitmap: &Arc) -> Arc { + pub fn bitmap_linear_and( + offset: u64, + bitmap: &Arc, + compression: CompressionCode, + ) -> Arc { let bitmap = bitmap.actual.read().unwrap().clone(); - // TODO: compression codes let actual = servicepoint::Command::BitmapLinearAnd( offset as usize, bitmap, - CompressionCode::Uncompressed, + servicepoint::CompressionCode::try_from(compression as u16) + .unwrap(), ); Self::internal_new(actual) } #[uniffi::constructor] - pub fn bitmap_linear_or(offset: u64, bitmap: &Arc) -> Arc { + pub fn bitmap_linear_or( + offset: u64, + bitmap: &Arc, + compression: CompressionCode, + ) -> Arc { let bitmap = bitmap.actual.read().unwrap().clone(); - // TODO: compression codes let actual = servicepoint::Command::BitmapLinearOr( offset as usize, bitmap, - CompressionCode::Uncompressed, + servicepoint::CompressionCode::try_from(compression as u16) + .unwrap(), ); Self::internal_new(actual) } #[uniffi::constructor] - pub fn bitmap_linear_xor(offset: u64, bitmap: &Arc) -> Arc { + pub fn bitmap_linear_xor( + offset: u64, + bitmap: &Arc, + compression: CompressionCode, + ) -> Arc { let bitmap = bitmap.actual.read().unwrap().clone(); - // TODO: compression codes let actual = servicepoint::Command::BitmapLinearXor( offset as usize, bitmap, - CompressionCode::Uncompressed, + servicepoint::CompressionCode::try_from(compression as u16) + .unwrap(), ); Self::internal_new(actual) } + + #[uniffi::constructor] + pub fn clone(other: &Arc) -> Arc { + Self::internal_new(other.actual.clone()) + } } diff --git a/crates/servicepoint_binding_uniffi/src/compression_code.rs b/crates/servicepoint_binding_uniffi/src/compression_code.rs new file mode 100644 index 0000000..078230a --- /dev/null +++ b/crates/servicepoint_binding_uniffi/src/compression_code.rs @@ -0,0 +1,14 @@ +#[repr(u16)] +#[derive(Debug, Clone, Copy, PartialEq, uniffi::Enum)] +pub enum CompressionCode { + /// no compression + Uncompressed = 0x0, + /// compress using flate2 with zlib header + Zlib = 0x677a, + /// compress using bzip2 + Bzip2 = 0x627a, + /// compress using lzma + Lzma = 0x6c7a, + /// compress using Zstandard + Zstd = 0x7a73, +} diff --git a/crates/servicepoint_binding_uniffi/src/lib.rs b/crates/servicepoint_binding_uniffi/src/lib.rs index 89823ad..975cd9c 100644 --- a/crates/servicepoint_binding_uniffi/src/lib.rs +++ b/crates/servicepoint_binding_uniffi/src/lib.rs @@ -4,5 +4,6 @@ mod bitmap; mod bitvec; mod brightness_grid; mod command; +mod compression_code; mod connection; mod errors;