Skip to content

Commit

Permalink
expose new command to uniffi API
Browse files Browse the repository at this point in the history
  • Loading branch information
kaesaecracker committed Jan 12, 2025
1 parent b27f7d1 commit 66f2663
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,10 @@ public static extern CommandSafeHandle uniffi_servicepoint_binding_uniffi_fn_con
public static extern CommandSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_command_hard_reset(ref RustCallStatus _uniffi_out_err
);

[DllImport("servicepoint_binding_uniffi")]
public static extern CommandSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_command_utf8_data(ulong @offsetX,ulong @offsetY,CharGridSafeHandle @grid,ref RustCallStatus _uniffi_out_err
);

[DllImport("servicepoint_binding_uniffi")]
public static extern sbyte uniffi_servicepoint_binding_uniffi_fn_method_command_equals(CommandSafeHandle @ptr,CommandSafeHandle @other,ref RustCallStatus _uniffi_out_err
);
Expand Down Expand Up @@ -1255,6 +1259,10 @@ public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_construc
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_constructor_command_hard_reset(
);

[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_constructor_command_utf8_data(
);

[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_constructor_connection_new(
);
Expand Down Expand Up @@ -1697,6 +1705,12 @@ static void uniffiCheckApiChecksums() {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_command_hard_reset` checksum `62130`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_constructor_command_utf8_data();
if (checksum != 2263) {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_command_utf8_data` checksum `2263`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_constructor_connection_new();
if (checksum != 30445) {
Expand Down Expand Up @@ -2671,6 +2685,13 @@ public static Command HardReset() {
));
}

public static Command Utf8Data(ulong @offsetX, ulong @offsetY, CharGrid @grid) {
return new Command(
_UniffiHelpers.RustCall( (ref RustCallStatus _status) =>
_UniFFILib.uniffi_servicepoint_binding_uniffi_fn_constructor_command_utf8_data(FfiConverterUInt64.INSTANCE.Lower(@offsetX), FfiConverterUInt64.INSTANCE.Lower(@offsetY), FfiConverterTypeCharGrid.INSTANCE.Lower(@grid), ref _status)
));
}


}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,9 @@ module UniFFILib
attach_function :uniffi_servicepoint_binding_uniffi_fn_constructor_command_hard_reset,
[RustCallStatus.by_ref],
:pointer
attach_function :uniffi_servicepoint_binding_uniffi_fn_constructor_command_utf8_data,
[:uint64, :uint64, :pointer, RustCallStatus.by_ref],
:pointer
attach_function :uniffi_servicepoint_binding_uniffi_fn_method_command_equals,
[:pointer, :pointer, RustCallStatus.by_ref],
:int8
Expand Down Expand Up @@ -1188,6 +1191,9 @@ module UniFFILib
attach_function :uniffi_servicepoint_binding_uniffi_checksum_constructor_command_hard_reset,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_servicepoint_binding_uniffi_checksum_constructor_command_utf8_data,
[RustCallStatus.by_ref],
:uint16
attach_function :uniffi_servicepoint_binding_uniffi_checksum_constructor_connection_new,
[RustCallStatus.by_ref],
:uint16
Expand Down Expand Up @@ -1817,6 +1823,15 @@ def self.hard_reset()
# and just create a new instance with the required pointer.
return _uniffi_allocate(ServicepointBindingUniffi.rust_call(:uniffi_servicepoint_binding_uniffi_fn_constructor_command_hard_reset,))
end
def self.utf8_data(offset_x, offset_y, grid)
offset_x = ServicepointBindingUniffi::uniffi_in_range(offset_x, "u64", 0, 2**64)
offset_y = ServicepointBindingUniffi::uniffi_in_range(offset_y, "u64", 0, 2**64)
grid = grid
# Call the (fallible) function before creating any half-baked object instances.
# Lightly yucky way to bypass the usual "initialize" logic
# and just create a new instance with the required pointer.
return _uniffi_allocate(ServicepointBindingUniffi.rust_call(:uniffi_servicepoint_binding_uniffi_fn_constructor_command_utf8_data,offset_x,offset_y,(CharGrid._uniffi_lower grid)))
end


def equals(other)
Expand Down
13 changes: 13 additions & 0 deletions crates/servicepoint_binding_uniffi/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::bitmap::Bitmap;
use crate::bitvec::BitVec;
use crate::brightness_grid::BrightnessGrid;
use crate::char_grid::CharGrid;
use crate::compression_code::CompressionCode;
use crate::cp437_grid::Cp437Grid;
use crate::errors::ServicePointError;
Expand Down Expand Up @@ -151,6 +152,18 @@ impl Command {
Self::internal_new(actual)
}

#[uniffi::constructor]
pub fn utf8_data(
offset_x: u64,
offset_y: u64,
grid: &Arc<CharGrid>,
) -> Arc<Self> {
let origin = Origin::new(offset_x as usize, offset_y as usize);
let grid = grid.actual.read().unwrap().clone();
let actual = servicepoint::Command::Utf8Data(origin, grid);
Self::internal_new(actual)
}

#[uniffi::constructor]
pub fn clone(other: &Arc<Self>) -> Arc<Self> {
Self::internal_new(other.actual.clone())
Expand Down

0 comments on commit 66f2663

Please sign in to comment.