add uniffi CharGrid

This commit is contained in:
Vinzenz Schroeter 2024-11-10 15:08:39 +01:00
parent 9553d9fe42
commit d0d70c079e
9 changed files with 755 additions and 10 deletions

View file

@ -17,7 +17,7 @@ uniffi = { version = "0.25.0", features = ["build"] }
[dependencies]
uniffi = { version = "0.25.0" }
thiserror = "1.0.66"
thiserror.workspace = true
[dependencies.servicepoint]
version = "0.11.0"

View file

@ -0,0 +1,31 @@
namespace ServicePoint.Tests;
public class CharGridTests
{
[Fact]
public void BasicFunctions()
{
var grid = new CharGrid(8, 2);
Assert.Equal("\0", grid.Get(0, 0));
Assert.Equal("\0", grid.Get(grid.Width() - 1, grid.Height() - 1));
grid.Fill(" ");
Assert.Equal(" ", grid.Get(1, 1));
grid.Set(1, 1, "-");
Assert.Equal("-", grid.Get(1, 1));
Assert.Throws<PanicException>(() => grid.Get(8, 2));
}
[Fact]
public void RowAndCol()
{
var grid = new CharGrid(3, 2);
Assert.Equal("\0\0\0", grid.GetRow(0));
grid.Fill(" ");
Assert.Equal(" ", grid.GetCol(1));
Assert.Throws<CharGridException.OutOfBounds>(() => grid.GetCol(3));
Assert.Throws<CharGridException.InvalidSeriesLength>(() => grid.SetRow(1, "Text"));
grid.SetRow(1, "Foo");
Assert.Equal("Foo", grid.GetRow(1));
Assert.Equal(" o", grid.GetCol(2));
}
}

View file

@ -37,6 +37,6 @@ public class CommandTests
[Fact]
public void BitmapLinearWinSendable()
{
_connection.Send(Command.BitmapLinearWin(0, 0, Bitmap.NewMaxSized()));
_connection.Send(Command.BitmapLinearWin(0, 0, Bitmap.NewMaxSized(), CompressionCode.Uncompressed));
}
}

View file

@ -563,6 +563,71 @@ static class _UniFFILib {
public static extern ulong uniffi_servicepoint_binding_uniffi_fn_method_brightnessgrid_width(BrightnessGridSafeHandle @ptr,ref RustCallStatus _uniffi_out_err
);
[DllImport("servicepoint_binding_uniffi")]
public static extern void uniffi_servicepoint_binding_uniffi_fn_free_chargrid(
IntPtr ptr,ref RustCallStatus _uniffi_out_err
);
[DllImport("servicepoint_binding_uniffi")]
public static extern CharGridSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_chargrid_clone(CharGridSafeHandle @other,ref RustCallStatus _uniffi_out_err
);
[DllImport("servicepoint_binding_uniffi")]
public static extern CharGridSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_chargrid_load(RustBuffer @data,ref RustCallStatus _uniffi_out_err
);
[DllImport("servicepoint_binding_uniffi")]
public static extern CharGridSafeHandle uniffi_servicepoint_binding_uniffi_fn_constructor_chargrid_new(ulong @width,ulong @height,ref RustCallStatus _uniffi_out_err
);
[DllImport("servicepoint_binding_uniffi")]
public static extern RustBuffer uniffi_servicepoint_binding_uniffi_fn_method_chargrid_as_string(CharGridSafeHandle @ptr,ref RustCallStatus _uniffi_out_err
);
[DllImport("servicepoint_binding_uniffi")]
public static extern sbyte uniffi_servicepoint_binding_uniffi_fn_method_chargrid_equals(CharGridSafeHandle @ptr,CharGridSafeHandle @other,ref RustCallStatus _uniffi_out_err
);
[DllImport("servicepoint_binding_uniffi")]
public static extern void uniffi_servicepoint_binding_uniffi_fn_method_chargrid_fill(CharGridSafeHandle @ptr,RustBuffer @value,ref RustCallStatus _uniffi_out_err
);
[DllImport("servicepoint_binding_uniffi")]
public static extern RustBuffer uniffi_servicepoint_binding_uniffi_fn_method_chargrid_get(CharGridSafeHandle @ptr,ulong @x,ulong @y,ref RustCallStatus _uniffi_out_err
);
[DllImport("servicepoint_binding_uniffi")]
public static extern RustBuffer uniffi_servicepoint_binding_uniffi_fn_method_chargrid_get_col(CharGridSafeHandle @ptr,ulong @x,ref RustCallStatus _uniffi_out_err
);
[DllImport("servicepoint_binding_uniffi")]
public static extern RustBuffer uniffi_servicepoint_binding_uniffi_fn_method_chargrid_get_row(CharGridSafeHandle @ptr,ulong @y,ref RustCallStatus _uniffi_out_err
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ulong uniffi_servicepoint_binding_uniffi_fn_method_chargrid_height(CharGridSafeHandle @ptr,ref RustCallStatus _uniffi_out_err
);
[DllImport("servicepoint_binding_uniffi")]
public static extern void uniffi_servicepoint_binding_uniffi_fn_method_chargrid_set(CharGridSafeHandle @ptr,ulong @x,ulong @y,RustBuffer @value,ref RustCallStatus _uniffi_out_err
);
[DllImport("servicepoint_binding_uniffi")]
public static extern void uniffi_servicepoint_binding_uniffi_fn_method_chargrid_set_col(CharGridSafeHandle @ptr,ulong @x,RustBuffer @col,ref RustCallStatus _uniffi_out_err
);
[DllImport("servicepoint_binding_uniffi")]
public static extern void uniffi_servicepoint_binding_uniffi_fn_method_chargrid_set_row(CharGridSafeHandle @ptr,ulong @y,RustBuffer @row,ref RustCallStatus _uniffi_out_err
);
[DllImport("servicepoint_binding_uniffi")]
public static extern Cp437GridSafeHandle uniffi_servicepoint_binding_uniffi_fn_method_chargrid_to_cp437(CharGridSafeHandle @ptr,ref RustCallStatus _uniffi_out_err
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ulong uniffi_servicepoint_binding_uniffi_fn_method_chargrid_width(CharGridSafeHandle @ptr,ref RustCallStatus _uniffi_out_err
);
[DllImport("servicepoint_binding_uniffi")]
public static extern void uniffi_servicepoint_binding_uniffi_fn_free_command(
IntPtr ptr,ref RustCallStatus _uniffi_out_err
@ -678,6 +743,10 @@ static class _UniFFILib {
public static extern void uniffi_servicepoint_binding_uniffi_fn_method_cp437grid_set(Cp437GridSafeHandle @ptr,ulong @x,ulong @y,byte @value,ref RustCallStatus _uniffi_out_err
);
[DllImport("servicepoint_binding_uniffi")]
public static extern CharGridSafeHandle uniffi_servicepoint_binding_uniffi_fn_method_cp437grid_to_utf8(Cp437GridSafeHandle @ptr,ref RustCallStatus _uniffi_out_err
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ulong uniffi_servicepoint_binding_uniffi_fn_method_cp437grid_width(Cp437GridSafeHandle @ptr,ref RustCallStatus _uniffi_out_err
);
@ -990,6 +1059,54 @@ static class _UniFFILib {
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_method_brightnessgrid_width(
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_as_string(
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_equals(
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_fill(
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_get(
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_get_col(
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_get_row(
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_height(
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_set(
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_set_col(
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_set_row(
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_to_cp437(
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_width(
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_method_command_equals(
);
@ -1022,6 +1139,10 @@ static class _UniFFILib {
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_method_cp437grid_set(
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_method_cp437grid_to_utf8(
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_method_cp437grid_width(
);
@ -1066,6 +1187,18 @@ static class _UniFFILib {
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_constructor_brightnessgrid_new(
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_constructor_chargrid_clone(
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_constructor_chargrid_load(
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_constructor_chargrid_new(
);
[DllImport("servicepoint_binding_uniffi")]
public static extern ushort uniffi_servicepoint_binding_uniffi_checksum_constructor_command_bitmap_linear(
);
@ -1268,6 +1401,78 @@ static class _UniFFILib {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_method_brightnessgrid_width` checksum `26384`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_as_string();
if (checksum != 46581) {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_as_string` checksum `46581`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_equals();
if (checksum != 17533) {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_equals` checksum `17533`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_fill();
if (checksum != 56996) {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_fill` checksum `56996`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_get();
if (checksum != 1334) {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_get` checksum `1334`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_get_col();
if (checksum != 64158) {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_get_col` checksum `64158`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_get_row();
if (checksum != 39411) {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_get_row` checksum `39411`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_height();
if (checksum != 13068) {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_height` checksum `13068`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_set();
if (checksum != 64815) {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_set` checksum `64815`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_set_col();
if (checksum != 43727) {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_set_col` checksum `43727`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_set_row();
if (checksum != 19756) {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_set_row` checksum `19756`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_to_cp437();
if (checksum != 19261) {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_to_cp437` checksum `19261`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_width();
if (checksum != 48963) {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_method_chargrid_width` checksum `48963`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_method_command_equals();
if (checksum != 20763) {
@ -1316,6 +1521,12 @@ static class _UniFFILib {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_method_cp437grid_set` checksum `8371`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_method_cp437grid_to_utf8();
if (checksum != 21516) {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_method_cp437grid_to_utf8` checksum `21516`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_method_cp437grid_width();
if (checksum != 36872) {
@ -1382,6 +1593,24 @@ static class _UniFFILib {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_brightnessgrid_new` checksum `4979`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_constructor_chargrid_clone();
if (checksum != 61241) {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_chargrid_clone` checksum `61241`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_constructor_chargrid_load();
if (checksum != 47815) {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_chargrid_load` checksum `47815`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_constructor_chargrid_new();
if (checksum != 13303) {
throw new UniffiContractChecksumException($"ServicePoint: uniffi bindings expected function `uniffi_servicepoint_binding_uniffi_checksum_constructor_chargrid_new` checksum `13303`, library returned `{checksum}`");
}
}
{
var checksum = _UniFFILib.uniffi_servicepoint_binding_uniffi_checksum_constructor_command_bitmap_linear();
if (checksum != 18079) {
@ -2122,6 +2351,196 @@ class FfiConverterTypeBrightnessGrid: FfiConverter<BrightnessGrid, BrightnessGri
public interface ICharGrid {
String AsString();
bool Equals(CharGrid @other);
/// <exception cref="CharGridException"></exception>
void Fill(String @value);
String Get(ulong @x, ulong @y);
/// <exception cref="CharGridException"></exception>
String GetCol(ulong @x);
/// <exception cref="CharGridException"></exception>
String GetRow(ulong @y);
ulong Height();
/// <exception cref="CharGridException"></exception>
void Set(ulong @x, ulong @y, String @value);
/// <exception cref="CharGridException"></exception>
void SetCol(ulong @x, String @col);
/// <exception cref="CharGridException"></exception>
void SetRow(ulong @y, String @row);
Cp437Grid ToCp437();
ulong Width();
}
public class CharGridSafeHandle: FFISafeHandle {
public CharGridSafeHandle(): base() {
}
public CharGridSafeHandle(IntPtr pointer): base(pointer) {
}
override protected bool ReleaseHandle() {
_UniffiHelpers.RustCall((ref RustCallStatus status) => {
_UniFFILib.uniffi_servicepoint_binding_uniffi_fn_free_chargrid(this.handle, ref status);
});
return true;
}
}
public class CharGrid: FFIObject<CharGridSafeHandle>, ICharGrid {
public CharGrid(CharGridSafeHandle pointer): base(pointer) {}
public CharGrid(ulong @width, ulong @height) :
this(
_UniffiHelpers.RustCall( (ref RustCallStatus _status) =>
_UniFFILib.uniffi_servicepoint_binding_uniffi_fn_constructor_chargrid_new(FfiConverterUInt64.INSTANCE.Lower(@width), FfiConverterUInt64.INSTANCE.Lower(@height), ref _status)
)) {}
public String AsString() {
return FfiConverterString.INSTANCE.Lift(
_UniffiHelpers.RustCall( (ref RustCallStatus _status) =>
_UniFFILib.uniffi_servicepoint_binding_uniffi_fn_method_chargrid_as_string(this.GetHandle(), ref _status)
));
}
public bool Equals(CharGrid @other) {
return FfiConverterBoolean.INSTANCE.Lift(
_UniffiHelpers.RustCall( (ref RustCallStatus _status) =>
_UniFFILib.uniffi_servicepoint_binding_uniffi_fn_method_chargrid_equals(this.GetHandle(), FfiConverterTypeCharGrid.INSTANCE.Lower(@other), ref _status)
));
}
/// <exception cref="CharGridException"></exception>
public void Fill(String @value) {
_UniffiHelpers.RustCallWithError(FfiConverterTypeCharGridException.INSTANCE, (ref RustCallStatus _status) =>
_UniFFILib.uniffi_servicepoint_binding_uniffi_fn_method_chargrid_fill(this.GetHandle(), FfiConverterString.INSTANCE.Lower(@value), ref _status)
);
}
public String Get(ulong @x, ulong @y) {
return FfiConverterString.INSTANCE.Lift(
_UniffiHelpers.RustCall( (ref RustCallStatus _status) =>
_UniFFILib.uniffi_servicepoint_binding_uniffi_fn_method_chargrid_get(this.GetHandle(), FfiConverterUInt64.INSTANCE.Lower(@x), FfiConverterUInt64.INSTANCE.Lower(@y), ref _status)
));
}
/// <exception cref="CharGridException"></exception>
public String GetCol(ulong @x) {
return FfiConverterString.INSTANCE.Lift(
_UniffiHelpers.RustCallWithError(FfiConverterTypeCharGridException.INSTANCE, (ref RustCallStatus _status) =>
_UniFFILib.uniffi_servicepoint_binding_uniffi_fn_method_chargrid_get_col(this.GetHandle(), FfiConverterUInt64.INSTANCE.Lower(@x), ref _status)
));
}
/// <exception cref="CharGridException"></exception>
public String GetRow(ulong @y) {
return FfiConverterString.INSTANCE.Lift(
_UniffiHelpers.RustCallWithError(FfiConverterTypeCharGridException.INSTANCE, (ref RustCallStatus _status) =>
_UniFFILib.uniffi_servicepoint_binding_uniffi_fn_method_chargrid_get_row(this.GetHandle(), FfiConverterUInt64.INSTANCE.Lower(@y), ref _status)
));
}
public ulong Height() {
return FfiConverterUInt64.INSTANCE.Lift(
_UniffiHelpers.RustCall( (ref RustCallStatus _status) =>
_UniFFILib.uniffi_servicepoint_binding_uniffi_fn_method_chargrid_height(this.GetHandle(), ref _status)
));
}
/// <exception cref="CharGridException"></exception>
public void Set(ulong @x, ulong @y, String @value) {
_UniffiHelpers.RustCallWithError(FfiConverterTypeCharGridException.INSTANCE, (ref RustCallStatus _status) =>
_UniFFILib.uniffi_servicepoint_binding_uniffi_fn_method_chargrid_set(this.GetHandle(), FfiConverterUInt64.INSTANCE.Lower(@x), FfiConverterUInt64.INSTANCE.Lower(@y), FfiConverterString.INSTANCE.Lower(@value), ref _status)
);
}
/// <exception cref="CharGridException"></exception>
public void SetCol(ulong @x, String @col) {
_UniffiHelpers.RustCallWithError(FfiConverterTypeCharGridException.INSTANCE, (ref RustCallStatus _status) =>
_UniFFILib.uniffi_servicepoint_binding_uniffi_fn_method_chargrid_set_col(this.GetHandle(), FfiConverterUInt64.INSTANCE.Lower(@x), FfiConverterString.INSTANCE.Lower(@col), ref _status)
);
}
/// <exception cref="CharGridException"></exception>
public void SetRow(ulong @y, String @row) {
_UniffiHelpers.RustCallWithError(FfiConverterTypeCharGridException.INSTANCE, (ref RustCallStatus _status) =>
_UniFFILib.uniffi_servicepoint_binding_uniffi_fn_method_chargrid_set_row(this.GetHandle(), FfiConverterUInt64.INSTANCE.Lower(@y), FfiConverterString.INSTANCE.Lower(@row), ref _status)
);
}
public Cp437Grid ToCp437() {
return FfiConverterTypeCp437Grid.INSTANCE.Lift(
_UniffiHelpers.RustCall( (ref RustCallStatus _status) =>
_UniFFILib.uniffi_servicepoint_binding_uniffi_fn_method_chargrid_to_cp437(this.GetHandle(), ref _status)
));
}
public ulong Width() {
return FfiConverterUInt64.INSTANCE.Lift(
_UniffiHelpers.RustCall( (ref RustCallStatus _status) =>
_UniFFILib.uniffi_servicepoint_binding_uniffi_fn_method_chargrid_width(this.GetHandle(), ref _status)
));
}
public static CharGrid Clone(CharGrid @other) {
return new CharGrid(
_UniffiHelpers.RustCall( (ref RustCallStatus _status) =>
_UniFFILib.uniffi_servicepoint_binding_uniffi_fn_constructor_chargrid_clone(FfiConverterTypeCharGrid.INSTANCE.Lower(@other), ref _status)
));
}
public static CharGrid Load(String @data) {
return new CharGrid(
_UniffiHelpers.RustCall( (ref RustCallStatus _status) =>
_UniFFILib.uniffi_servicepoint_binding_uniffi_fn_constructor_chargrid_load(FfiConverterString.INSTANCE.Lower(@data), ref _status)
));
}
}
class FfiConverterTypeCharGrid: FfiConverter<CharGrid, CharGridSafeHandle> {
public static FfiConverterTypeCharGrid INSTANCE = new FfiConverterTypeCharGrid();
public override CharGridSafeHandle Lower(CharGrid value) {
return value.GetHandle();
}
public override CharGrid Lift(CharGridSafeHandle value) {
return new CharGrid(value);
}
public override CharGrid Read(BigEndianStream stream) {
return Lift(new CharGridSafeHandle(new IntPtr(stream.ReadLong())));
}
public override int AllocationSize(CharGrid value) {
return 8;
}
public override void Write(CharGrid value, BigEndianStream stream) {
stream.WriteLong(Lower(value).DangerousGetRawFfiValue().ToInt64());
}
}
public interface ICommand {
bool Equals(Command @other);
@ -2355,6 +2774,8 @@ public interface ICp437Grid {
void Set(ulong @x, ulong @y, byte @value);
CharGrid ToUtf8();
ulong Width();
}
@ -2422,6 +2843,13 @@ public class Cp437Grid: FFIObject<Cp437GridSafeHandle>, ICp437Grid {
}
public CharGrid ToUtf8() {
return FfiConverterTypeCharGrid.INSTANCE.Lift(
_UniffiHelpers.RustCall( (ref RustCallStatus _status) =>
_UniFFILib.uniffi_servicepoint_binding_uniffi_fn_method_cp437grid_to_utf8(this.GetHandle(), ref _status)
));
}
public ulong Width() {
return FfiConverterUInt64.INSTANCE.Lift(
_UniffiHelpers.RustCall( (ref RustCallStatus _status) =>
@ -2476,6 +2904,121 @@ class FfiConverterTypeCp437Grid: FfiConverter<Cp437Grid, Cp437GridSafeHandle> {
public class CharGridException: UniffiException {
// Each variant is a nested class
public class StringNotOneChar : CharGridException {
// Members
public String @value;
// Constructor
public StringNotOneChar(
String @value) {
this.@value = @value;
}
}
public class InvalidSeriesLength : CharGridException {
// Members
public ulong @actual;
public ulong @expected;
// Constructor
public InvalidSeriesLength(
ulong @actual,
ulong @expected) {
this.@actual = @actual;
this.@expected = @expected;
}
}
public class OutOfBounds : CharGridException {
// Members
public ulong @index;
public ulong @size;
// Constructor
public OutOfBounds(
ulong @index,
ulong @size) {
this.@index = @index;
this.@size = @size;
}
}
}
class FfiConverterTypeCharGridException : FfiConverterRustBuffer<CharGridException>, CallStatusErrorHandler<CharGridException> {
public static FfiConverterTypeCharGridException INSTANCE = new FfiConverterTypeCharGridException();
public override CharGridException Read(BigEndianStream stream) {
var value = stream.ReadInt();
switch (value) {
case 1:
return new CharGridException.StringNotOneChar(
FfiConverterString.INSTANCE.Read(stream));
case 2:
return new CharGridException.InvalidSeriesLength(
FfiConverterUInt64.INSTANCE.Read(stream),
FfiConverterUInt64.INSTANCE.Read(stream));
case 3:
return new CharGridException.OutOfBounds(
FfiConverterUInt64.INSTANCE.Read(stream),
FfiConverterUInt64.INSTANCE.Read(stream));
default:
throw new InternalException(String.Format("invalid error value '{0}' in FfiConverterTypeCharGridException.Read()", value));
}
}
public override int AllocationSize(CharGridException value) {
switch (value) {
case CharGridException.StringNotOneChar variant_value:
return 4
+ FfiConverterString.INSTANCE.AllocationSize(variant_value.@value);
case CharGridException.InvalidSeriesLength variant_value:
return 4
+ FfiConverterUInt64.INSTANCE.AllocationSize(variant_value.@actual)
+ FfiConverterUInt64.INSTANCE.AllocationSize(variant_value.@expected);
case CharGridException.OutOfBounds variant_value:
return 4
+ FfiConverterUInt64.INSTANCE.AllocationSize(variant_value.@index)
+ FfiConverterUInt64.INSTANCE.AllocationSize(variant_value.@size);
default:
throw new InternalException(String.Format("invalid error value '{0}' in FfiConverterTypeCharGridException.AllocationSize()", value));
}
}
public override void Write(CharGridException value, BigEndianStream stream) {
switch (value) {
case CharGridException.StringNotOneChar variant_value:
stream.WriteInt(1);
FfiConverterString.INSTANCE.Write(variant_value.@value, stream);
break;
case CharGridException.InvalidSeriesLength variant_value:
stream.WriteInt(2);
FfiConverterUInt64.INSTANCE.Write(variant_value.@actual, stream);
FfiConverterUInt64.INSTANCE.Write(variant_value.@expected, stream);
break;
case CharGridException.OutOfBounds variant_value:
stream.WriteInt(3);
FfiConverterUInt64.INSTANCE.Write(variant_value.@index, stream);
FfiConverterUInt64.INSTANCE.Write(variant_value.@size, stream);
break;
default:
throw new InternalException(String.Format("invalid error value '{0}' in FfiConverterTypeCharGridException.Write()", value));
}
}
}
public enum CompressionCode: int {
Uncompressed,

View file

@ -75,6 +75,12 @@ impl BrightnessGrid {
}
pub fn copy_raw(&self) -> Vec<u8> {
self.actual.read().unwrap().data_ref().iter().map(u8::from).collect()
self.actual
.read()
.unwrap()
.data_ref()
.iter()
.map(u8::from)
.collect()
}
}

View file

@ -0,0 +1,163 @@
use servicepoint::{Grid, SeriesError};
use std::convert::Into;
use std::sync::{Arc, RwLock};
use crate::cp437_grid::Cp437Grid;
#[derive(uniffi::Object)]
pub struct CharGrid {
pub(crate) actual: RwLock<servicepoint::CharGrid>,
}
#[derive(uniffi::Error, thiserror::Error, Debug)]
pub enum CharGridError {
#[error("Exactly one character was expected, but {value:?} was provided")]
StringNotOneChar { value: String },
#[error("The provided series was expected to have a length of {expected}, but was {actual}")]
InvalidSeriesLength { actual: u64, expected: u64 },
#[error("The index {index} was out of bounds for size {size}")]
OutOfBounds { index: u64, size: u64 },
}
#[uniffi::export]
impl CharGrid {
#[uniffi::constructor]
pub fn new(width: u64, height: u64) -> Arc<Self> {
Self::internal_new(servicepoint::CharGrid::new(
width as usize,
height as usize,
))
}
#[uniffi::constructor]
pub fn load(data: String) -> Arc<Self> {
Self::internal_new(servicepoint::CharGrid::from(&*data))
}
#[uniffi::constructor]
pub fn clone(other: &Arc<Self>) -> Arc<Self> {
Self::internal_new(other.actual.read().unwrap().clone())
}
pub fn set(
&self,
x: u64,
y: u64,
value: String,
) -> Result<(), CharGridError> {
let value = Self::str_to_char(value)?;
self.actual
.write()
.unwrap()
.set(x as usize, y as usize, value);
Ok(())
}
pub fn get(&self, x: u64, y: u64) -> String {
self.actual
.read()
.unwrap()
.get(x as usize, y as usize)
.into()
}
pub fn fill(&self, value: String) -> Result<(), CharGridError> {
let value = Self::str_to_char(value)?;
self.actual.write().unwrap().fill(value);
Ok(())
}
pub fn width(&self) -> u64 {
self.actual.read().unwrap().width() as u64
}
pub fn height(&self) -> u64 {
self.actual.read().unwrap().height() as u64
}
pub fn equals(&self, other: &CharGrid) -> bool {
let a = self.actual.read().unwrap();
let b = other.actual.read().unwrap();
*a == *b
}
pub fn as_string(&self) -> String {
let grid = self.actual.read().unwrap();
String::from(&*grid)
}
pub fn set_row(&self, y: u64, row: String) -> Result<(), CharGridError> {
self.actual
.write()
.unwrap()
.set_row(y as usize, &*row.chars().collect::<Vec<_>>())
.map_err(CharGridError::from)
}
pub fn set_col(&self, x: u64, col: String) -> Result<(), CharGridError> {
self.actual
.write()
.unwrap()
.set_row(x as usize, &*col.chars().collect::<Vec<_>>())
.map_err(CharGridError::from)
}
pub fn get_row(&self, y: u64) -> Result<String, CharGridError> {
self.actual
.read()
.unwrap()
.get_row(y as usize)
.map(move |vec| String::from_iter(vec))
.ok_or(CharGridError::OutOfBounds {index: y, size: self.height()})
}
pub fn get_col(&self, x: u64) -> Result<String, CharGridError> {
self.actual
.read()
.unwrap()
.get_col(x as usize)
.map(move |vec| String::from_iter(vec))
.ok_or(CharGridError::OutOfBounds {index: x, size: self.width()})
}
pub fn to_cp437(&self) -> Arc<Cp437Grid> {
Cp437Grid::internal_new(servicepoint::Cp437Grid::from(&*self.actual.read().unwrap()))
}
}
impl CharGrid {
pub(crate) fn internal_new(actual: servicepoint::CharGrid) -> Arc<Self> {
Arc::new(Self {
actual: RwLock::new(actual),
})
}
fn str_to_char(value: String) -> Result<char, CharGridError> {
if value.len() != 1 {
return Err(CharGridError::StringNotOneChar {
value,
});
}
let value = value.chars().nth(0).unwrap();
Ok(value)
}
}
impl From<SeriesError> for CharGridError {
fn from(e: SeriesError) -> Self {
match e {
SeriesError::OutOfBounds { index, size } => {
CharGridError::OutOfBounds {
index: index as u64,
size: size as u64,
}
}
SeriesError::InvalidLength { actual, expected } => {
CharGridError::InvalidSeriesLength {
actual: actual as u64,
expected: expected as u64,
}
}
}
}
}

View file

@ -1,5 +1,6 @@
use servicepoint::{DataRef, Grid};
use std::sync::{Arc, RwLock};
use crate::char_grid::CharGrid;
#[derive(uniffi::Object)]
pub struct Cp437Grid {
@ -7,7 +8,7 @@ pub struct Cp437Grid {
}
impl Cp437Grid {
fn internal_new(actual: servicepoint::Cp437Grid) -> Arc<Self> {
pub(crate) fn internal_new(actual: servicepoint::Cp437Grid) -> Arc<Self> {
Arc::new(Self {
actual: RwLock::new(actual),
})
@ -46,11 +47,7 @@ impl Cp437Grid {
}
pub fn get(&self, x: u64, y: u64) -> u8 {
self.actual
.read()
.unwrap()
.get(x as usize, y as usize)
.into()
self.actual.read().unwrap().get(x as usize, y as usize)
}
pub fn fill(&self, value: u8) {
@ -73,4 +70,8 @@ impl Cp437Grid {
pub fn copy_raw(&self) -> Vec<u8> {
self.actual.read().unwrap().data_ref().to_vec()
}
pub fn to_utf8(&self) -> Arc<CharGrid> {
CharGrid::internal_new(servicepoint::CharGrid::from(&*self.actual.read().unwrap()))
}
}

View file

@ -3,6 +3,7 @@ uniffi::setup_scaffolding!();
mod bitmap;
mod bitvec;
mod brightness_grid;
mod char_grid;
mod command;
mod compression_code;
mod connection;