servicepoint/crates/servicepoint_binding_cs
2024-10-20 13:34:21 +02:00
..
examples/lang_cs annotate which parameters are consumed, move constants 2024-10-19 15:31:54 +02:00
ServicePoint add sp_packet_from_parts, regenerate C header 2024-10-20 13:34:21 +02:00
ServicePoint.Tests add unit tests for null handling, fix assertion in rust code 2024-10-20 13:33:12 +02:00
src more documentation 2024-05-28 20:37:55 +02:00
build.rs add docs to public methods instead of native ones 2024-10-19 14:35:03 +02:00
Cargo.toml generate most of the c# binding with a fork of csbindgen 2024-10-19 14:21:50 +02:00
README.md update C# README 2024-10-20 12:29:26 +02:00
ServicePoint.sln add first C# unit test 2024-10-20 12:29:45 +02:00

ServicePoint

In CCCB, there is a big pixel matrix hanging on the wall. It is called "Service Point Display" or "Airport Display". This crate contains C# bindings for the servicepoint library, enabling users to parse, encode and send packets to this display via UDP.

Examples

using ServicePoint;

using var connection = Connection.Open("127.0.0.1:2342");
using var pixels = new Bitmap(Constants.PixelWidth, Constants.PixelHeight);

while (true)
{
    pixels.Fill(true);
    connection.Send(Command.BitmapLinearWin(0, 0, pixels.Clone()));
    Thread.Sleep(5000);

    pixels.Fill(false);
    connection.Send(Command.BitmapLinearWin(0, 0, pixels));
    Thread.Sleep(5000);
}

An example including project files is available as part of this crate.

You can also check out the unit tests for usage examples for some things.

Installation

NuGet packages are not a good way to distribute native projects (relevant issue). Because of that, there is no NuGet package you can use directly. Including this repository as a submodule and building from source is the recommended way of using the library.

git submodule add https://github.com/cccb/servicepoint.git
git commit -m "add servicepoint submodule"

You can now reference servicepoint_binding_cs/src/ServicePoint.csproj in your project. The rust library will automatically be built.

Please provide more information in the form of an issue if you need the build to copy a different library file for your platform.

Note on stability

This library is still in early development. You can absolutely use it, and it works, but expect minor breaking changes with every version bump.

Documentation

There are multiple suboptimal ways to read the documentation for this.

You can read the rust docs, as the types and methods in C# should have the same names as those in rust.

You can also read the documentation comments on each method. Those are copied from the C API, which means they will include the this parameter in the description. They are markdown formatted and may render in one line in your IDE - this is a known issue.

Differences to other supported languages

C# does have some differences, especially regarding safety. In rust, the compiler will tell you when trying to use an object that has already been dropped or moved. In the C API, the user promises to keep things like that in mind, and will get assertion failures or segmentation faults if you are lucky when doing something wrong.

The C# compiler will not help you to keep track of the lifetime of rust objects, but you also do not have to worry about unnoticed memory corruption in most cases, as the library knows when you pass objects to methods that consume them and raises a NullReferenceException instead. When objects are garbage collected on the C# side, the rust object is freed as well.

Currently, lifetime tracking may not work reliably in multithreaded code. You should prevent concurrent write access.

Everything else

Look at the main project README for further information.