wip update to next servicepoint version

This commit is contained in:
Vinzenz Schroeter 2025-04-11 21:40:49 +02:00
parent ac3c470b44
commit 5377f13ea1
14 changed files with 937 additions and 235 deletions

9
Cargo.lock generated
View file

@ -98,9 +98,9 @@ dependencies = [
[[package]]
name = "cbindgen"
version = "0.27.0"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fce8dd7fcfcbf3a0a87d8f515194b49d6135acab73e18bd380d1d93bb1a15eb"
checksum = "eadd868a2ce9ca38de7eeafdcec9c7065ef89b42b32f0839278d55f35c54d1ff"
dependencies = [
"clap",
"heck",
@ -407,9 +407,8 @@ dependencies = [
[[package]]
name = "servicepoint"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93b52049be55a15fe37c13249d7f96aa8a5de56e1a41838e74a822ee8316a0c4"
version = "0.13.2"
source = "git+https://git.berlin.ccc.de/servicepoint/servicepoint/?branch=next#fe67160974d9fed542eb37e5e9a202eaf6fe00dc"
dependencies = [
"bitvec",
"bzip2",

View file

@ -15,14 +15,14 @@ keywords = ["cccb", "cccb-servicepoint", "cbindgen"]
crate-type = ["staticlib", "cdylib", "rlib"]
[build-dependencies]
cbindgen = "0.27.0"
cbindgen = "0.28.0"
[dependencies.servicepoint]
version = "0.13.1"
features = ["all_compressions"]
[dependencies]
servicepoint = { features = ["all_compressions"], git = "https://git.berlin.ccc.de/servicepoint/servicepoint/", branch = "next" }
[lints.rust]
missing-docs = "warn"
unsafe_op_in_unsafe_fn = "warn"
[package.metadata.docs.rs]
all-features = true

695
examples/lang_c/Cargo.lock generated Normal file
View file

@ -0,0 +1,695 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "adler2"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
[[package]]
name = "anstream"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
[[package]]
name = "anstyle-parse"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e"
dependencies = [
"anstyle",
"once_cell",
"windows-sys",
]
[[package]]
name = "bitflags"
version = "2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
[[package]]
name = "bitvec"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c"
dependencies = [
"funty",
"radium",
"tap",
"wyz",
]
[[package]]
name = "bzip2"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49ecfb22d906f800d4fe833b6282cf4dc1c298f5057ca0b5445e5c209735ca47"
dependencies = [
"bzip2-sys",
]
[[package]]
name = "bzip2-sys"
version = "0.1.13+1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "225bff33b2141874fe80d71e07d6eec4f85c5c216453dd96388240f96e1acc14"
dependencies = [
"cc",
"pkg-config",
]
[[package]]
name = "cbindgen"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eadd868a2ce9ca38de7eeafdcec9c7065ef89b42b32f0839278d55f35c54d1ff"
dependencies = [
"clap",
"heck",
"indexmap",
"log",
"proc-macro2",
"quote",
"serde",
"serde_json",
"syn",
"tempfile",
"toml",
]
[[package]]
name = "cc"
version = "1.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e3a13707ac958681c13b39b458c073d0d9bc8a22cb1b2f4c8e55eb72c13f362"
dependencies = [
"jobserver",
"libc",
"shlex",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "4.5.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8aa86934b44c19c50f87cc2790e19f54f7a67aedb64101c2e1a2e5ecfb73944"
dependencies = [
"clap_builder",
]
[[package]]
name = "clap_builder"
version = "4.5.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2414dbb2dd0695280da6ea9261e327479e9d37b0630f6b53ba2a11c60c679fd9"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_lex"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
[[package]]
name = "colorchoice"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
[[package]]
name = "crc32fast"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3"
dependencies = [
"cfg-if",
]
[[package]]
name = "equivalent"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]]
name = "errno"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e"
dependencies = [
"libc",
"windows-sys",
]
[[package]]
name = "fastrand"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
[[package]]
name = "flate2"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece"
dependencies = [
"crc32fast",
"miniz_oxide",
]
[[package]]
name = "funty"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c"
[[package]]
name = "getrandom"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0"
dependencies = [
"cfg-if",
"libc",
"r-efi",
"wasi",
]
[[package]]
name = "hashbrown"
version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "indexmap"
version = "2.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "itoa"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "jobserver"
version = "0.1.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38f262f097c174adebe41eb73d66ae9c06b2844fb0da69969647bbddd9b0538a"
dependencies = [
"getrandom",
"libc",
]
[[package]]
name = "lang_c"
version = "0.1.0"
dependencies = [
"cc",
"servicepoint_binding_c",
]
[[package]]
name = "libc"
version = "0.2.171"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6"
[[package]]
name = "linux-raw-sys"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12"
[[package]]
name = "log"
version = "0.4.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
[[package]]
name = "memchr"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "miniz_oxide"
version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3be647b768db090acb35d5ec5db2b0e1f1de11133ca123b9eacf5137868f892a"
dependencies = [
"adler2",
]
[[package]]
name = "once_cell"
version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "pkg-config"
version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
[[package]]
name = "proc-macro2"
version = "1.0.94"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]
[[package]]
name = "r-efi"
version = "5.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74765f6d916ee2faa39bc8e68e4f3ed8949b48cccdac59983d287a7cb71ce9c5"
[[package]]
name = "radium"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09"
[[package]]
name = "rust-lzma"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d62915608f6cee1d7f2fc00f28b4f058ff79d6e4ec3c2fe0006b09b52437c84"
dependencies = [
"pkg-config",
"vcpkg",
]
[[package]]
name = "rustix"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d97817398dd4bb2e6da002002db259209759911da105da92bec29ccb12cf58bf"
dependencies = [
"bitflags",
"errno",
"libc",
"linux-raw-sys",
"windows-sys",
]
[[package]]
name = "ryu"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
[[package]]
name = "serde"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.219"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
dependencies = [
"itoa",
"memchr",
"ryu",
"serde",
]
[[package]]
name = "serde_spanned"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1"
dependencies = [
"serde",
]
[[package]]
name = "servicepoint"
version = "0.13.2"
source = "git+https://git.berlin.ccc.de/servicepoint/servicepoint/?branch=next#75d24f658764dea251e28c7067446f3ccfbb89b0"
dependencies = [
"bitvec",
"bzip2",
"flate2",
"log",
"once_cell",
"rust-lzma",
"thiserror",
"zstd",
]
[[package]]
name = "servicepoint_binding_c"
version = "0.13.1"
dependencies = [
"cbindgen",
"servicepoint",
]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "strsim"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "syn"
version = "2.0.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "tap"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
[[package]]
name = "tempfile"
version = "3.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7437ac7763b9b123ccf33c338a5cc1bac6f69b45a136c19bdd8a65e3916435bf"
dependencies = [
"fastrand",
"getrandom",
"once_cell",
"rustix",
"windows-sys",
]
[[package]]
name = "thiserror"
version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "toml"
version = "0.8.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd87a5cdd6ffab733b2f74bc4fd7ee5fff6634124999ac278c35fc78c6120148"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
]
[[package]]
name = "toml_datetime"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.22.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474"
dependencies = [
"indexmap",
"serde",
"serde_spanned",
"toml_datetime",
"winnow",
]
[[package]]
name = "unicode-ident"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
name = "wasi"
version = "0.14.2+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
dependencies = [
"wit-bindgen-rt",
]
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "winnow"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63d3fcd9bba44b03821e7d699eeee959f3126dcc4aa8e4ae18ec617c2a5cea10"
dependencies = [
"memchr",
]
[[package]]
name = "wit-bindgen-rt"
version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
dependencies = [
"bitflags",
]
[[package]]
name = "wyz"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed"
dependencies = [
"tap",
]
[[package]]
name = "zstd"
version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a"
dependencies = [
"zstd-safe",
]
[[package]]
name = "zstd-safe"
version = "7.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f49c4d5f0abb602a93fb8736af2a4f4dd9512e36f7f570d66e65ff867ed3b9d"
dependencies = [
"zstd-sys",
]
[[package]]
name = "zstd-sys"
version = "2.0.15+zstd.1.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb81183ddd97d0c74cedf1d50d85c8d08c1b8b68ee863bdee9e706eedba1a237"
dependencies = [
"cc",
"pkg-config",
]

View file

@ -1,4 +1,4 @@
/* Generated with cbindgen:0.27.0 */
/* Generated with cbindgen:0.28.0 */
/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */
@ -168,19 +168,6 @@ typedef struct SPCharGrid SPCharGrid;
*/
typedef struct SPCommand SPCommand;
/**
* A connection to the display.
*
* # Examples
*
* ```C
* CConnection connection = sp_connection_open("172.23.42.29:2342");
* if (connection != NULL)
* sp_connection_send_command(connection, sp_command_clear());
* ```
*/
typedef struct SPConnection SPConnection;
/**
* A C-wrapper for grid containing codepage 437 characters.
*
@ -202,6 +189,19 @@ typedef struct SPCp437Grid SPCp437Grid;
*/
typedef struct SPPacket SPPacket;
/**
* A connection to the display.
*
* # Examples
*
* ```C
* CConnection connection = sp_connection_open("172.23.42.29:2342");
* if (connection != NULL)
* sp_connection_send_command(connection, sp_command_clear());
* ```
*/
typedef struct SPUdpConnection SPUdpConnection;
/**
* Represents a span of memory (`&mut [u8]` ) as a struct usable by C code.
*
@ -290,7 +290,7 @@ void sp_bitmap_fill(SPBitmap *bitmap, bool value);
*
* [SPCommand]: [crate::SPCommand]
*/
void sp_bitmap_free(SPBitmap *bitmap);
void sp_bitmap_free(SPBitmap **bitmap);
/**
* Gets the current value at the specified position in the [SPBitmap].
@ -341,13 +341,18 @@ size_t sp_bitmap_height(const SPBitmap *bitmap);
* - `width`: size in pixels in x-direction
* - `height`: size in pixels in y-direction
*
* returns: [SPBitmap] that contains a copy of the provided data. Will never return NULL.
* returns: [SPBitmap] that contains a copy of the provided data, or NULL in case of an error.
*
* # Errors
*
* In the following cases, this function will return NULL:
*
* - when the dimensions and data size do not match exactly.
* - when the width is not dividable by 8
*
* # Panics
*
* - when `data` is NULL
* - when the dimensions and data size do not match exactly.
* - when the width is not dividable by 8
*
* # Safety
*
@ -370,9 +375,11 @@ SPBitmap *sp_bitmap_load(size_t width,
* - `width`: size in pixels in x-direction
* - `height`: size in pixels in y-direction
*
* returns: [SPBitmap] initialized to all pixels off. Will never return NULL.
* returns: [SPBitmap] initialized to all pixels off, or NULL in case of an error.
*
* # Panics
* # Errors
*
* In the following cases, this function will return NULL:
*
* - when the width is not dividable by 8
*
@ -1206,7 +1213,7 @@ SPCommand *sp_command_bitmap_linear_or(size_t offset,
SPCommand *sp_command_bitmap_linear_win(size_t x,
size_t y,
SPBitmap *bitmap,
SPCompressionCode compression_code);
SPCompressionCode compression);
/**
* Set pixel data according to a xor-mask starting at the offset.
@ -1449,21 +1456,7 @@ SPCommand *sp_command_utf8_data(size_t x,
SPCharGrid *grid);
/**
* Creates a new instance of [SPConnection] for testing that does not actually send anything.
*
* returns: a new instance. Will never return NULL.
*
* # Safety
*
* The caller has to make sure that:
*
* - the returned instance is freed in some way, either by using a consuming function or
* by explicitly calling `sp_connection_free`.
*/
SPConnection *sp_connection_fake(void);
/**
* Closes and deallocates a [SPConnection].
* Closes and deallocates a [SPUdpConnection].
*
* # Panics
*
@ -1473,13 +1466,13 @@ SPConnection *sp_connection_fake(void);
*
* The caller has to make sure that:
*
* - `connection` points to a valid [SPConnection]
* - `connection` points to a valid [SPUdpConnection]
* - `connection` is not used concurrently or after this call
*/
void sp_connection_free(SPConnection *connection);
void sp_connection_free(SPUdpConnection *connection);
/**
* Creates a new instance of [SPConnection].
* Creates a new instance of [SPUdpConnection].
*
* returns: NULL if connection fails, or connected instance
*
@ -1494,10 +1487,10 @@ void sp_connection_free(SPConnection *connection);
* - the returned instance is freed in some way, either by using a consuming function or
* by explicitly calling `sp_connection_free`.
*/
SPConnection *sp_connection_open(const char *host);
SPUdpConnection *sp_connection_open(const char *host);
/**
* Sends a [SPCommand] to the display using the [SPConnection].
* Sends a [SPCommand] to the display using the [SPUdpConnection].
*
* The passed `command` gets consumed.
*
@ -1512,15 +1505,15 @@ SPConnection *sp_connection_open(const char *host);
*
* The caller has to make sure that:
*
* - `connection` points to a valid instance of [SPConnection]
* - `connection` points to a valid instance of [SPUdpConnection]
* - `command` points to a valid instance of [SPPacket]
* - `command` is not used concurrently or after this call
*/
bool sp_connection_send_command(const SPConnection *connection,
bool sp_connection_send_command(const SPUdpConnection *connection,
SPCommand *command);
/**
* Sends a [SPPacket] to the display using the [SPConnection].
* Sends a [SPPacket] to the display using the [SPUdpConnection].
*
* The passed `packet` gets consumed.
*
@ -1535,11 +1528,11 @@ bool sp_connection_send_command(const SPConnection *connection,
*
* The caller has to make sure that:
*
* - `connection` points to a valid instance of [SPConnection]
* - `connection` points to a valid instance of [SPUdpConnection]
* - `packet` points to a valid instance of [SPPacket]
* - `packet` is not used concurrently or after this call
*/
bool sp_connection_send_packet(const SPConnection *connection,
bool sp_connection_send_packet(const SPUdpConnection *connection,
SPPacket *packet);
/**

View file

@ -2,7 +2,7 @@
#include "servicepoint.h"
int main(void) {
SPConnection *connection = sp_connection_open("localhost:2342");
SPUdpConnection *connection = sp_connection_open("localhost:2342");
if (connection == NULL)
return 1;

View file

@ -3,7 +3,7 @@
//! prefix `sp_bitmap_`
use servicepoint::{DataRef, Grid};
use std::ptr::NonNull;
use std::ptr::{null_mut, NonNull};
use crate::byte_slice::SPByteSlice;
@ -26,9 +26,11 @@ pub struct SPBitmap(pub(crate) servicepoint::Bitmap);
/// - `width`: size in pixels in x-direction
/// - `height`: size in pixels in y-direction
///
/// returns: [SPBitmap] initialized to all pixels off. Will never return NULL.
/// returns: [SPBitmap] initialized to all pixels off, or NULL in case of an error.
///
/// # Panics
/// # Errors
///
/// In the following cases, this function will return NULL:
///
/// - when the width is not dividable by 8
///
@ -42,9 +44,12 @@ pub struct SPBitmap(pub(crate) servicepoint::Bitmap);
pub unsafe extern "C" fn sp_bitmap_new(
width: usize,
height: usize,
) -> NonNull<SPBitmap> {
let result = Box::new(SPBitmap(servicepoint::Bitmap::new(width, height)));
NonNull::from(Box::leak(result))
) -> *mut SPBitmap {
if let Some(bitmap) = servicepoint::Bitmap::new(width, height) {
Box::leak(Box::new(SPBitmap(bitmap)))
}else {
std::ptr::null_mut()
}
}
/// Creates a new [SPBitmap] with a size matching the screen.
@ -70,13 +75,18 @@ pub unsafe extern "C" fn sp_bitmap_new_screen_sized() -> NonNull<SPBitmap> {
/// - `width`: size in pixels in x-direction
/// - `height`: size in pixels in y-direction
///
/// returns: [SPBitmap] that contains a copy of the provided data. Will never return NULL.
/// returns: [SPBitmap] that contains a copy of the provided data, or NULL in case of an error.
///
/// # Errors
///
/// In the following cases, this function will return NULL:
///
/// - when the dimensions and data size do not match exactly.
/// - when the width is not dividable by 8
///
/// # Panics
///
/// - when `data` is NULL
/// - when the dimensions and data size do not match exactly.
/// - when the width is not dividable by 8
///
/// # Safety
///
@ -91,12 +101,14 @@ pub unsafe extern "C" fn sp_bitmap_load(
height: usize,
data: *const u8,
data_length: usize,
) -> NonNull<SPBitmap> {
) -> *mut SPBitmap {
assert!(!data.is_null());
let data = std::slice::from_raw_parts(data, data_length);
let result =
Box::new(SPBitmap(servicepoint::Bitmap::load(width, height, data)));
NonNull::from(Box::leak(result))
let data = unsafe {std::slice::from_raw_parts(data, data_length)};
if let Ok(bitmap) = servicepoint::Bitmap::load(width, height, data) {
Box::leak(Box::new(SPBitmap(bitmap)))
}else {
std::ptr::null_mut()
}
}
/// Clones a [SPBitmap].
@ -120,7 +132,7 @@ pub unsafe extern "C" fn sp_bitmap_clone(
bitmap: *const SPBitmap,
) -> NonNull<SPBitmap> {
assert!(!bitmap.is_null());
let result = Box::new(SPBitmap((*bitmap).0.clone()));
let result = Box::new(SPBitmap(unsafe {(*bitmap).0.clone()}));
NonNull::from(Box::leak(result))
}
@ -142,7 +154,7 @@ pub unsafe extern "C" fn sp_bitmap_clone(
#[no_mangle]
pub unsafe extern "C" fn sp_bitmap_free(bitmap: *mut SPBitmap) {
assert!(!bitmap.is_null());
_ = Box::from_raw(bitmap);
_ = unsafe {Box::from_raw(bitmap)};
}
/// Gets the current value at the specified position in the [SPBitmap].
@ -170,7 +182,7 @@ pub unsafe extern "C" fn sp_bitmap_get(
y: usize,
) -> bool {
assert!(!bitmap.is_null());
(*bitmap).0.get(x, y)
unsafe {(*bitmap).0.get(x, y)}
}
/// Sets the value of the specified position in the [SPBitmap].
@ -202,7 +214,7 @@ pub unsafe extern "C" fn sp_bitmap_set(
value: bool,
) {
assert!(!bitmap.is_null());
(*bitmap).0.set(x, y, value);
unsafe {(*bitmap).0.set(x, y, value)};
}
/// Sets the state of all pixels in the [SPBitmap].
@ -225,7 +237,7 @@ pub unsafe extern "C" fn sp_bitmap_set(
#[no_mangle]
pub unsafe extern "C" fn sp_bitmap_fill(bitmap: *mut SPBitmap, value: bool) {
assert!(!bitmap.is_null());
(*bitmap).0.fill(value);
unsafe {(*bitmap).0.fill(value)};
}
/// Gets the width in pixels of the [SPBitmap] instance.
@ -246,7 +258,7 @@ pub unsafe extern "C" fn sp_bitmap_fill(bitmap: *mut SPBitmap, value: bool) {
#[no_mangle]
pub unsafe extern "C" fn sp_bitmap_width(bitmap: *const SPBitmap) -> usize {
assert!(!bitmap.is_null());
(*bitmap).0.width()
unsafe {(*bitmap).0.width()}
}
/// Gets the height in pixels of the [SPBitmap] instance.
@ -267,7 +279,7 @@ pub unsafe extern "C" fn sp_bitmap_width(bitmap: *const SPBitmap) -> usize {
#[no_mangle]
pub unsafe extern "C" fn sp_bitmap_height(bitmap: *const SPBitmap) -> usize {
assert!(!bitmap.is_null());
(*bitmap).0.height()
unsafe {(*bitmap).0.height()}
}
/// Gets an unsafe reference to the data of the [SPBitmap] instance.
@ -288,7 +300,7 @@ pub unsafe extern "C" fn sp_bitmap_unsafe_data_ref(
bitmap: *mut SPBitmap,
) -> SPByteSlice {
assert!(!bitmap.is_null());
let data = (*bitmap).0.data_ref_mut();
let data = unsafe {(*bitmap).0.data_ref_mut()};
SPByteSlice {
start: NonNull::new(data.as_mut_ptr_range().start).unwrap(),
length: data.len(),

View file

@ -79,7 +79,7 @@ pub unsafe extern "C" fn sp_bitvec_load(
data_length: usize,
) -> NonNull<SPBitVec> {
assert!(!data.is_null());
let data = std::slice::from_raw_parts(data, data_length);
let data = unsafe {std::slice::from_raw_parts(data, data_length)};
let result = Box::new(SPBitVec(servicepoint::BitVec::from_slice(data)));
NonNull::from(Box::leak(result))
}
@ -105,7 +105,7 @@ pub unsafe extern "C" fn sp_bitvec_clone(
bit_vec: *const SPBitVec,
) -> NonNull<SPBitVec> {
assert!(!bit_vec.is_null());
let result = Box::new((*bit_vec).clone());
let result = Box::new(unsafe {(*bit_vec).clone()});
NonNull::from(Box::leak(result))
}
@ -127,7 +127,7 @@ pub unsafe extern "C" fn sp_bitvec_clone(
#[no_mangle]
pub unsafe extern "C" fn sp_bitvec_free(bit_vec: *mut SPBitVec) {
assert!(!bit_vec.is_null());
_ = Box::from_raw(bit_vec);
_ = unsafe {Box::from_raw(bit_vec)};
}
/// Gets the value of a bit from the [SPBitVec].
@ -156,7 +156,7 @@ pub unsafe extern "C" fn sp_bitvec_get(
index: usize,
) -> bool {
assert!(!bit_vec.is_null());
*(*bit_vec).0.get(index).unwrap()
unsafe {*(*bit_vec).0.get(index).unwrap()}
}
/// Sets the value of a bit in the [SPBitVec].
@ -185,7 +185,7 @@ pub unsafe extern "C" fn sp_bitvec_set(
value: bool,
) {
assert!(!bit_vec.is_null());
(*bit_vec).0.set(index, value)
unsafe {(*bit_vec).0.set(index, value)}
}
/// Sets the value of all bits in the [SPBitVec].
@ -208,7 +208,7 @@ pub unsafe extern "C" fn sp_bitvec_set(
#[no_mangle]
pub unsafe extern "C" fn sp_bitvec_fill(bit_vec: *mut SPBitVec, value: bool) {
assert!(!bit_vec.is_null());
(*bit_vec).0.fill(value)
unsafe {(*bit_vec).0.fill(value)}
}
/// Gets the length of the [SPBitVec] in bits.
@ -229,7 +229,7 @@ pub unsafe extern "C" fn sp_bitvec_fill(bit_vec: *mut SPBitVec, value: bool) {
#[no_mangle]
pub unsafe extern "C" fn sp_bitvec_len(bit_vec: *const SPBitVec) -> usize {
assert!(!bit_vec.is_null());
(*bit_vec).0.len()
unsafe {(*bit_vec).0.len()}
}
/// Returns true if length is 0.
@ -250,7 +250,7 @@ pub unsafe extern "C" fn sp_bitvec_len(bit_vec: *const SPBitVec) -> usize {
#[no_mangle]
pub unsafe extern "C" fn sp_bitvec_is_empty(bit_vec: *const SPBitVec) -> bool {
assert!(!bit_vec.is_null());
(*bit_vec).0.is_empty()
unsafe {(*bit_vec).0.is_empty()}
}
/// Gets an unsafe reference to the data of the [SPBitVec] instance.
@ -275,7 +275,7 @@ pub unsafe extern "C" fn sp_bitvec_unsafe_data_ref(
bit_vec: *mut SPBitVec,
) -> SPByteSlice {
assert!(!bit_vec.is_null());
let data = (*bit_vec).0.as_raw_mut_slice();
let data = unsafe {(*bit_vec).0.as_raw_mut_slice()};
SPByteSlice {
start: NonNull::new(data.as_mut_ptr_range().start).unwrap(),
length: data.len(),

View file

@ -77,14 +77,18 @@ pub unsafe extern "C" fn sp_brightness_grid_load(
height: usize,
data: *const u8,
data_length: usize,
) -> NonNull<SPBrightnessGrid> {
) -> *mut SPBrightnessGrid {
assert!(!data.is_null());
let data = std::slice::from_raw_parts(data, data_length);
let grid = servicepoint::ByteGrid::load(width, height, data);
let grid = servicepoint::BrightnessGrid::try_from(grid)
.expect("invalid brightness value");
let result = Box::new(SPBrightnessGrid(grid));
NonNull::from(Box::leak(result))
let data =unsafe { std::slice::from_raw_parts(data, data_length)};
let grid = match servicepoint::ByteGrid::load(width, height, data) {
None => return std::ptr::null_mut(),
Some(grid) => grid
};
if let Ok(grid )= servicepoint::BrightnessGrid::try_from(grid) {
Box::leak(Box::new(SPBrightnessGrid(grid)))
}else {
std::ptr::null_mut()
}
}
/// Clones a [SPBrightnessGrid].
@ -112,7 +116,7 @@ pub unsafe extern "C" fn sp_brightness_grid_clone(
brightness_grid: *const SPBrightnessGrid,
) -> NonNull<SPBrightnessGrid> {
assert!(!brightness_grid.is_null());
let result = Box::new((*brightness_grid).clone());
let result = Box::new(unsafe {(*brightness_grid).clone()});
NonNull::from(Box::leak(result))
}
@ -140,7 +144,7 @@ pub unsafe extern "C" fn sp_brightness_grid_free(
brightness_grid: *mut SPBrightnessGrid,
) {
assert!(!brightness_grid.is_null());
_ = Box::from_raw(brightness_grid);
_ = unsafe {Box::from_raw(brightness_grid)};
}
/// Gets the current value at the specified position.
@ -170,7 +174,7 @@ pub unsafe extern "C" fn sp_brightness_grid_get(
y: usize,
) -> u8 {
assert!(!brightness_grid.is_null());
(*brightness_grid).0.get(x, y).into()
unsafe {(*brightness_grid).0.get(x, y)}.into()
}
/// Sets the value of the specified position in the [SPBrightnessGrid].
@ -205,7 +209,7 @@ pub unsafe extern "C" fn sp_brightness_grid_set(
assert!(!brightness_grid.is_null());
let brightness = servicepoint::Brightness::try_from(value)
.expect("invalid brightness value");
(*brightness_grid).0.set(x, y, brightness);
unsafe {(*brightness_grid).0.set(x, y, brightness)};
}
/// Sets the value of all cells in the [SPBrightnessGrid].
@ -234,7 +238,7 @@ pub unsafe extern "C" fn sp_brightness_grid_fill(
assert!(!brightness_grid.is_null());
let brightness = servicepoint::Brightness::try_from(value)
.expect("invalid brightness value");
(*brightness_grid).0.fill(brightness);
unsafe {(*brightness_grid).0.fill(brightness)};
}
/// Gets the width of the [SPBrightnessGrid] instance.
@ -259,7 +263,7 @@ pub unsafe extern "C" fn sp_brightness_grid_width(
brightness_grid: *const SPBrightnessGrid,
) -> usize {
assert!(!brightness_grid.is_null());
(*brightness_grid).0.width()
unsafe {(*brightness_grid).0.width()}
}
/// Gets the height of the [SPBrightnessGrid] instance.
@ -284,7 +288,7 @@ pub unsafe extern "C" fn sp_brightness_grid_height(
brightness_grid: *const SPBrightnessGrid,
) -> usize {
assert!(!brightness_grid.is_null());
(*brightness_grid).0.height()
unsafe {(*brightness_grid).0.height()}
}
/// Gets an unsafe reference to the data of the [SPBrightnessGrid] instance.
@ -312,9 +316,9 @@ pub unsafe extern "C" fn sp_brightness_grid_unsafe_data_ref(
) -> SPByteSlice {
assert!(!brightness_grid.is_null());
assert_eq!(core::mem::size_of::<servicepoint::Brightness>(), 1);
let data = (*brightness_grid).0.data_ref_mut();
let data = unsafe {(*brightness_grid).0.data_ref_mut()};
// this assumes more about the memory layout than rust guarantees. yikes!
let data: &mut [u8] = transmute(data);
let data: &mut [u8] = unsafe {transmute(data)};
SPByteSlice {
start: NonNull::new(data.as_mut_ptr_range().start).unwrap(),
length: data.len(),

View file

@ -74,7 +74,7 @@ pub unsafe extern "C" fn sp_char_grid_load(
data_length: usize,
) -> NonNull<SPCharGrid> {
assert!(data.is_null());
let data = std::slice::from_raw_parts(data, data_length);
let data = unsafe {std::slice::from_raw_parts(data, data_length)};
let result = Box::new(SPCharGrid(
servicepoint::CharGrid::load_utf8(width, height, data.to_vec())
.unwrap(),
@ -103,7 +103,7 @@ pub unsafe extern "C" fn sp_char_grid_clone(
char_grid: *const SPCharGrid,
) -> NonNull<SPCharGrid> {
assert!(!char_grid.is_null());
let result = Box::new((*char_grid).clone());
let result = Box::new(unsafe{(*char_grid).clone()});
NonNull::from(Box::leak(result))
}
@ -125,7 +125,7 @@ pub unsafe extern "C" fn sp_char_grid_clone(
#[no_mangle]
pub unsafe extern "C" fn sp_char_grid_free(char_grid: *mut SPCharGrid) {
assert!(!char_grid.is_null());
_ = Box::from_raw(char_grid);
_ = unsafe {Box::from_raw(char_grid)};
}
/// Gets the current value at the specified position.
@ -153,7 +153,7 @@ pub unsafe extern "C" fn sp_char_grid_get(
y: usize,
) -> u32 {
assert!(!char_grid.is_null());
(*char_grid).0.get(x, y) as u32
unsafe {(*char_grid).0.get(x, y) as u32}
}
/// Sets the value of the specified position in the [SPCharGrid].
@ -187,7 +187,7 @@ pub unsafe extern "C" fn sp_char_grid_set(
value: u32,
) {
assert!(!char_grid.is_null());
(*char_grid).0.set(x, y, char::from_u32(value).unwrap());
unsafe {(*char_grid).0.set(x, y, char::from_u32(value).unwrap())};
}
/// Sets the value of all cells in the [SPCharGrid].
@ -213,7 +213,7 @@ pub unsafe extern "C" fn sp_char_grid_fill(
value: u32,
) {
assert!(!char_grid.is_null());
(*char_grid).0.fill(char::from_u32(value).unwrap());
unsafe {(*char_grid).0.fill(char::from_u32(value).unwrap())};
}
/// Gets the width of the [SPCharGrid] instance.
@ -236,7 +236,7 @@ pub unsafe extern "C" fn sp_char_grid_width(
char_grid: *const SPCharGrid,
) -> usize {
assert!(!char_grid.is_null());
(*char_grid).0.width()
unsafe {(*char_grid).0.width()}
}
/// Gets the height of the [SPCharGrid] instance.
@ -259,5 +259,5 @@ pub unsafe extern "C" fn sp_char_grid_height(
char_grid: *const SPCharGrid,
) -> usize {
assert!(!char_grid.is_null());
(*char_grid).0.height()
unsafe {(*char_grid).0.height()}
}

View file

@ -2,12 +2,12 @@
//!
//! prefix `sp_command_`
use std::ptr::{null_mut, NonNull};
use crate::{
SPBitVec, SPBitmap, SPBrightnessGrid, SPCharGrid, SPCompressionCode,
SPCp437Grid, SPPacket,
};
use servicepoint::{BinaryOperation, GlobalBrightnessCommand};
use std::ptr::NonNull;
/// A low-level display command.
///
@ -23,7 +23,7 @@ use crate::{
/// ```
///
/// [SPConnection]: [crate::SPConnection]
pub struct SPCommand(pub(crate) servicepoint::Command);
pub struct SPCommand(pub(crate) servicepoint::TypedCommand);
impl Clone for SPCommand {
fn clone(&self) -> Self {
@ -54,9 +54,9 @@ impl Clone for SPCommand {
pub unsafe extern "C" fn sp_command_try_from_packet(
packet: *mut SPPacket,
) -> *mut SPCommand {
let packet = *Box::from_raw(packet);
match servicepoint::Command::try_from(packet.0) {
Err(_) => null_mut(),
let packet = *unsafe{Box::from_raw(packet)};
match servicepoint::TypedCommand::try_from(packet.0) {
Err(_) => std::ptr::null_mut(),
Ok(command) => Box::into_raw(Box::new(SPCommand(command))),
}
}
@ -82,7 +82,7 @@ pub unsafe extern "C" fn sp_command_clone(
command: *const SPCommand,
) -> NonNull<SPCommand> {
assert!(!command.is_null());
let result = Box::new((*command).clone());
let result = Box::new(unsafe { (*command).clone() });
NonNull::from(Box::leak(result))
}
@ -106,7 +106,7 @@ pub unsafe extern "C" fn sp_command_clone(
/// by explicitly calling `sp_command_free`.
#[no_mangle]
pub unsafe extern "C" fn sp_command_clear() -> NonNull<SPCommand> {
let result = Box::new(SPCommand(servicepoint::Command::Clear));
let result = Box::new(SPCommand(servicepoint::ClearCommand.into()));
NonNull::from(Box::leak(result))
}
@ -124,7 +124,7 @@ pub unsafe extern "C" fn sp_command_clear() -> NonNull<SPCommand> {
/// by explicitly calling `sp_command_free`.
#[no_mangle]
pub unsafe extern "C" fn sp_command_hard_reset() -> NonNull<SPCommand> {
let result = Box::new(SPCommand(servicepoint::Command::HardReset));
let result = Box::new(SPCommand(servicepoint::HardResetCommand.into()));
NonNull::from(Box::leak(result))
}
@ -140,7 +140,7 @@ pub unsafe extern "C" fn sp_command_hard_reset() -> NonNull<SPCommand> {
/// by explicitly calling `sp_command_free`.
#[no_mangle]
pub unsafe extern "C" fn sp_command_fade_out() -> NonNull<SPCommand> {
let result = Box::new(SPCommand(servicepoint::Command::FadeOut));
let result = Box::new(SPCommand(servicepoint::FadeOutCommand.into()));
NonNull::from(Box::leak(result))
}
@ -164,8 +164,7 @@ pub unsafe extern "C" fn sp_command_brightness(
) -> NonNull<SPCommand> {
let brightness = servicepoint::Brightness::try_from(brightness)
.expect("invalid brightness");
let result =
Box::new(SPCommand(servicepoint::Command::Brightness(brightness)));
let result = Box::new(SPCommand(GlobalBrightnessCommand::from(brightness).into()));
NonNull::from(Box::leak(result))
}
@ -194,11 +193,11 @@ pub unsafe extern "C" fn sp_command_char_brightness(
grid: *mut SPBrightnessGrid,
) -> NonNull<SPCommand> {
assert!(!grid.is_null());
let byte_grid = *Box::from_raw(grid);
let result = Box::new(SPCommand(servicepoint::Command::CharBrightness(
servicepoint::Origin::new(x, y),
byte_grid.0,
)));
let byte_grid = unsafe { *Box::from_raw(grid) };
let result = Box::new(SPCommand(servicepoint::BrightnessGridCommand {
origin: servicepoint::Origin::new(x, y),
grid: byte_grid.0,
}.into()));
NonNull::from(Box::leak(result))
}
@ -232,15 +231,8 @@ pub unsafe extern "C" fn sp_command_bitmap_linear(
offset: usize,
bit_vec: *mut SPBitVec,
compression: SPCompressionCode,
) -> NonNull<SPCommand> {
assert!(!bit_vec.is_null());
let bit_vec = *Box::from_raw(bit_vec);
let result = Box::new(SPCommand(servicepoint::Command::BitmapLinear(
offset,
bit_vec.into(),
compression.try_into().expect("invalid compression code"),
)));
NonNull::from(Box::leak(result))
) -> *mut SPCommand {
unsafe {sp_command_bitmap_linear_internal(offset, bit_vec, compression, BinaryOperation::Overwrite)}
}
/// Set pixel data according to an and-mask starting at the offset.
@ -273,15 +265,8 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_and(
offset: usize,
bit_vec: *mut SPBitVec,
compression: SPCompressionCode,
) -> NonNull<SPCommand> {
assert!(!bit_vec.is_null());
let bit_vec = *Box::from_raw(bit_vec);
let result = Box::new(SPCommand(servicepoint::Command::BitmapLinearAnd(
offset,
bit_vec.into(),
compression.try_into().expect("invalid compression code"),
)));
NonNull::from(Box::leak(result))
) -> *mut SPCommand {
unsafe {sp_command_bitmap_linear_internal(offset, bit_vec, compression, BinaryOperation::Xor)}
}
/// Set pixel data according to an or-mask starting at the offset.
@ -314,15 +299,8 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_or(
offset: usize,
bit_vec: *mut SPBitVec,
compression: SPCompressionCode,
) -> NonNull<SPCommand> {
assert!(!bit_vec.is_null());
let bit_vec = *Box::from_raw(bit_vec);
let result = Box::new(SPCommand(servicepoint::Command::BitmapLinearOr(
offset,
bit_vec.into(),
compression.try_into().expect("invalid compression code"),
)));
NonNull::from(Box::leak(result))
) -> *mut SPCommand {
unsafe {sp_command_bitmap_linear_internal(offset, bit_vec, compression, BinaryOperation::Or)}
}
/// Set pixel data according to a xor-mask starting at the offset.
@ -355,15 +333,30 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_xor(
offset: usize,
bit_vec: *mut SPBitVec,
compression: SPCompressionCode,
) -> NonNull<SPCommand> {
) -> *mut SPCommand {
unsafe {sp_command_bitmap_linear_internal(offset, bit_vec, compression, BinaryOperation::Xor)}
}
#[inline]
unsafe fn sp_command_bitmap_linear_internal(
offset: usize,
bit_vec: *mut SPBitVec,
compression: SPCompressionCode,
operation: BinaryOperation
) -> *mut SPCommand {
assert!(!bit_vec.is_null());
let bit_vec = *Box::from_raw(bit_vec);
let result = Box::new(SPCommand(servicepoint::Command::BitmapLinearXor(
let bit_vec = unsafe { *Box::from_raw(bit_vec) };
let compression = match compression.try_into() {
Ok(compression) => compression,
Err(_) => return std::ptr::null_mut(),
};
let command = SPCommand(servicepoint::BitVecCommand {
offset,
bit_vec.into(),
compression.try_into().expect("invalid compression code"),
)));
NonNull::from(Box::leak(result))
operation,
bitvec: bit_vec.into(),
compression,
}.into());
Box::leak(Box::new(command))
}
/// Show codepage 437 encoded text on the screen.
@ -391,11 +384,12 @@ pub unsafe extern "C" fn sp_command_cp437_data(
grid: *mut SPCp437Grid,
) -> NonNull<SPCommand> {
assert!(!grid.is_null());
let grid = *Box::from_raw(grid);
let result = Box::new(SPCommand(servicepoint::Command::Cp437Data(
servicepoint::Origin::new(x, y),
grid.0,
)));
let grid = *unsafe{Box::from_raw(grid)};
let result = Box::new(SPCommand(servicepoint::Cp437GridCommand {
origin: servicepoint::Origin::new(x,
y),
grid: grid.0,
}.into()));
NonNull::from(Box::leak(result))
}
@ -424,11 +418,12 @@ pub unsafe extern "C" fn sp_command_utf8_data(
grid: *mut SPCharGrid,
) -> NonNull<SPCommand> {
assert!(!grid.is_null());
let grid = *Box::from_raw(grid);
let result = Box::new(SPCommand(servicepoint::Command::Utf8Data(
servicepoint::Origin::new(x, y),
grid.0,
)));
let grid = unsafe { *Box::from_raw(grid) };
let result = Box::new(SPCommand(servicepoint::CharGridCommand {
origin: servicepoint::Origin::new(x,
y),
grid: grid.0,
}.into()));
NonNull::from(Box::leak(result))
}
@ -457,18 +452,20 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_win(
x: usize,
y: usize,
bitmap: *mut SPBitmap,
compression_code: SPCompressionCode,
) -> NonNull<SPCommand> {
compression: SPCompressionCode,
) -> *mut SPCommand {
assert!(!bitmap.is_null());
let byte_grid = (*Box::from_raw(bitmap)).0;
let result = Box::new(SPCommand(servicepoint::Command::BitmapLinearWin(
servicepoint::Origin::new(x, y),
byte_grid,
compression_code
.try_into()
.expect("invalid compression code"),
)));
NonNull::from(Box::leak(result))
let bitmap = unsafe { *Box::from_raw(bitmap) }.0;
let compression = match compression.try_into() {
Ok(compression) => compression,
Err(_) => return std::ptr::null_mut(),
};
let command = SPCommand(servicepoint::BitmapCommand {
origin: servicepoint::Origin::new(x, y),
bitmap,
compression,
}.into());
Box::leak(Box::new(command))
}
/// Deallocates a [SPCommand].
@ -494,5 +491,5 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_win(
#[no_mangle]
pub unsafe extern "C" fn sp_command_free(command: *mut SPCommand) {
assert!(!command.is_null());
_ = Box::from_raw(command);
_ = unsafe { Box::from_raw(command) };
}

View file

@ -3,8 +3,7 @@
//! prefix `sp_connection_`
use std::ffi::{c_char, CStr};
use std::ptr::{null_mut, NonNull};
use servicepoint::Connection;
use crate::{SPCommand, SPPacket};
/// A connection to the display.
@ -16,7 +15,7 @@ use crate::{SPCommand, SPPacket};
/// if (connection != NULL)
/// sp_connection_send_command(connection, sp_command_clear());
/// ```
pub struct SPConnection(pub(crate) servicepoint::Connection);
pub struct SPConnection(pub(crate) servicepoint::UdpConnection);
/// Creates a new instance of [SPConnection].
///
@ -37,30 +36,30 @@ pub unsafe extern "C" fn sp_connection_open(
host: *const c_char,
) -> *mut SPConnection {
assert!(!host.is_null());
let host = CStr::from_ptr(host).to_str().expect("Bad encoding");
let connection = match servicepoint::Connection::open(host) {
Err(_) => return null_mut(),
let host = unsafe {CStr::from_ptr(host)}.to_str().expect("Bad encoding");
let connection = match servicepoint::UdpConnection::open(host) {
Err(_) => return std::ptr::null_mut(),
Ok(value) => value,
};
Box::into_raw(Box::new(SPConnection(connection)))
}
/// Creates a new instance of [SPConnection] for testing that does not actually send anything.
///
/// returns: a new instance. Will never return NULL.
///
/// # Safety
///
/// The caller has to make sure that:
///
/// - the returned instance is freed in some way, either by using a consuming function or
/// by explicitly calling `sp_connection_free`.
#[no_mangle]
pub unsafe extern "C" fn sp_connection_fake() -> NonNull<SPConnection> {
let result = Box::new(SPConnection(servicepoint::Connection::Fake));
NonNull::from(Box::leak(result))
}
// /// Creates a new instance of [SPUdpConnection] for testing that does not actually send anything.
// ///
// /// returns: a new instance. Will never return NULL.
// ///
// /// # Safety
// ///
// /// The caller has to make sure that:
// ///
// /// - the returned instance is freed in some way, either by using a consuming function or
// /// by explicitly calling `sp_connection_free`.
// #[no_mangle]
// pub unsafe extern "C" fn sp_connection_fake() -> NonNull<SPUdpConnection> {
// let result = Box::new(SPUdpConnection(servicepoint::Connection::Fake));
// NonNull::from(Box::leak(result))
// }
/// Sends a [SPPacket] to the display using the [SPConnection].
///
@ -87,8 +86,8 @@ pub unsafe extern "C" fn sp_connection_send_packet(
) -> bool {
assert!(!connection.is_null());
assert!(!packet.is_null());
let packet = Box::from_raw(packet);
(*connection).0.send((*packet).0).is_ok()
let packet = unsafe {Box::from_raw(packet)};
unsafe {(*connection).0.send((*packet).0)}.is_ok()
}
/// Sends a [SPCommand] to the display using the [SPConnection].
@ -116,8 +115,8 @@ pub unsafe extern "C" fn sp_connection_send_command(
) -> bool {
assert!(!connection.is_null());
assert!(!command.is_null());
let command = (*Box::from_raw(command)).0;
(*connection).0.send(command).is_ok()
let command = (*unsafe {Box::from_raw(command)}).0;
unsafe{(*connection).0.send(command)}.is_ok()
}
/// Closes and deallocates a [SPConnection].
@ -135,5 +134,5 @@ pub unsafe extern "C" fn sp_connection_send_command(
#[no_mangle]
pub unsafe extern "C" fn sp_connection_free(connection: *mut SPConnection) {
assert!(!connection.is_null());
_ = Box::from_raw(connection);
_ = unsafe {Box::from_raw(connection)};
}

View file

@ -43,6 +43,6 @@ impl TryFrom<SPCompressionCode> for CompressionCode {
type Error = ();
fn try_from(value: SPCompressionCode) -> Result<Self, Self::Error> {
CompressionCode::try_from(value as u16)
CompressionCode::try_from(value as u16).map_err(|_|())
}
}

View file

@ -69,13 +69,15 @@ pub unsafe extern "C" fn sp_cp437_grid_load(
height: usize,
data: *const u8,
data_length: usize,
) -> NonNull<SPCp437Grid> {
) -> *mut SPCp437Grid {
assert!(data.is_null());
let data = std::slice::from_raw_parts(data, data_length);
let result = Box::new(SPCp437Grid(servicepoint::Cp437Grid::load(
width, height, data,
)));
NonNull::from(Box::leak(result))
let data = unsafe{std::slice::from_raw_parts(data, data_length)};
let grid = servicepoint::Cp437Grid::load( width, height, data, );
if let Some(grid ) = grid {
Box::leak(Box::new(SPCp437Grid(grid)))
} else {
std::ptr::null_mut()
}
}
/// Clones a [SPCp437Grid].
@ -99,7 +101,7 @@ pub unsafe extern "C" fn sp_cp437_grid_clone(
cp437_grid: *const SPCp437Grid,
) -> NonNull<SPCp437Grid> {
assert!(!cp437_grid.is_null());
let result = Box::new((*cp437_grid).clone());
let result = Box::new(unsafe {(*cp437_grid).clone()});
NonNull::from(Box::leak(result))
}
@ -121,7 +123,7 @@ pub unsafe extern "C" fn sp_cp437_grid_clone(
#[no_mangle]
pub unsafe extern "C" fn sp_cp437_grid_free(cp437_grid: *mut SPCp437Grid) {
assert!(!cp437_grid.is_null());
_ = Box::from_raw(cp437_grid);
_ = unsafe {Box::from_raw(cp437_grid)};
}
/// Gets the current value at the specified position.
@ -149,7 +151,7 @@ pub unsafe extern "C" fn sp_cp437_grid_get(
y: usize,
) -> u8 {
assert!(!cp437_grid.is_null());
(*cp437_grid).0.get(x, y)
unsafe{(*cp437_grid).0.get(x, y)}
}
/// Sets the value of the specified position in the [SPCp437Grid].
@ -183,7 +185,7 @@ pub unsafe extern "C" fn sp_cp437_grid_set(
value: u8,
) {
assert!(!cp437_grid.is_null());
(*cp437_grid).0.set(x, y, value);
unsafe {(*cp437_grid).0.set(x, y, value)};
}
/// Sets the value of all cells in the [SPCp437Grid].
@ -209,7 +211,7 @@ pub unsafe extern "C" fn sp_cp437_grid_fill(
value: u8,
) {
assert!(!cp437_grid.is_null());
(*cp437_grid).0.fill(value);
unsafe {(*cp437_grid).0.fill(value)};
}
/// Gets the width of the [SPCp437Grid] instance.
@ -232,7 +234,7 @@ pub unsafe extern "C" fn sp_cp437_grid_width(
cp437_grid: *const SPCp437Grid,
) -> usize {
assert!(!cp437_grid.is_null());
(*cp437_grid).0.width()
unsafe {(*cp437_grid).0.width()}
}
/// Gets the height of the [SPCp437Grid] instance.
@ -255,7 +257,7 @@ pub unsafe extern "C" fn sp_cp437_grid_height(
cp437_grid: *const SPCp437Grid,
) -> usize {
assert!(!cp437_grid.is_null());
(*cp437_grid).0.height()
unsafe {(*cp437_grid).0.height()}
}
/// Gets an unsafe reference to the data of the [SPCp437Grid] instance.
@ -277,7 +279,7 @@ pub unsafe extern "C" fn sp_cp437_grid_height(
pub unsafe extern "C" fn sp_cp437_grid_unsafe_data_ref(
cp437_grid: *mut SPCp437Grid,
) -> SPByteSlice {
let data = (*cp437_grid).0.data_ref_mut();
let data = unsafe {(*cp437_grid).0.data_ref_mut()};
SPByteSlice {
start: NonNull::new(data.as_mut_ptr_range().start).unwrap(),
length: data.len(),

View file

@ -2,7 +2,7 @@
//!
//! prefix `sp_packet_`
use std::ptr::{null_mut, NonNull};
use std::ptr::{NonNull};
use crate::SPCommand;
@ -29,11 +29,12 @@ pub struct SPPacket(pub(crate) servicepoint::Packet);
#[no_mangle]
pub unsafe extern "C" fn sp_packet_from_command(
command: *mut SPCommand,
) -> NonNull<SPPacket> {
) -> *mut SPPacket {
assert!(!command.is_null());
let command = *Box::from_raw(command);
let result = Box::new(SPPacket(command.0.into()));
NonNull::from(Box::leak(result))
let command = unsafe {*Box::from_raw(command)};
if let Ok(packet) = command.0.try_into() {
Box::leak(Box::new(SPPacket(packet)))
} else { std::ptr::null_mut() }
}
/// Tries to load a [SPPacket] from the passed array with the specified length.
@ -58,9 +59,9 @@ pub unsafe extern "C" fn sp_packet_try_load(
length: usize,
) -> *mut SPPacket {
assert!(!data.is_null());
let data = std::slice::from_raw_parts(data, length);
let data = unsafe {std::slice::from_raw_parts(data, length)};
match servicepoint::Packet::try_from(data) {
Err(_) => null_mut(),
Err(_) => std::ptr::null_mut(),
Ok(packet) => Box::into_raw(Box::new(SPPacket(packet))),
}
}
@ -104,7 +105,7 @@ pub unsafe extern "C" fn sp_packet_from_parts(
let payload = if payload.is_null() {
vec![]
} else {
let payload = std::slice::from_raw_parts(payload, payload_len);
let payload = unsafe {std::slice::from_raw_parts(payload, payload_len) };
Vec::from(payload)
};
@ -143,7 +144,7 @@ pub unsafe extern "C" fn sp_packet_clone(
packet: *const SPPacket,
) -> NonNull<SPPacket> {
assert!(!packet.is_null());
let result = Box::new(SPPacket((*packet).0.clone()));
let result = Box::new(SPPacket(unsafe {(*packet).0.clone()}));
NonNull::from(Box::leak(result))
}
@ -162,5 +163,5 @@ pub unsafe extern "C" fn sp_packet_clone(
#[no_mangle]
pub unsafe extern "C" fn sp_packet_free(packet: *mut SPPacket) {
assert!(!packet.is_null());
_ = Box::from_raw(packet)
_ = unsafe {Box::from_raw(packet)}
}