separate types for c api
This commit is contained in:
		
							parent
							
								
									c554fbd800
								
							
						
					
					
						commit
						555d917d96
					
				
					 11 changed files with 648 additions and 162 deletions
				
			
		|  | @ -2,7 +2,7 @@ | |||
| 
 | ||||
| use clap::Parser; | ||||
| 
 | ||||
| use servicepoint::{Command, Connection, Cp473Grid, Grid, Origin}; | ||||
| use servicepoint::{Command, Connection, Cp437Grid, Grid, Origin}; | ||||
| 
 | ||||
| #[derive(Parser, Debug)] | ||||
| struct Cli { | ||||
|  | @ -33,7 +33,7 @@ fn main() { | |||
| 
 | ||||
|     let max_width = cli.text.iter().map(|t| t.len()).max().unwrap(); | ||||
| 
 | ||||
|     let mut chars = Cp473Grid::new(max_width, cli.text.len()); | ||||
|     let mut chars = Cp437Grid::new(max_width, cli.text.len()); | ||||
|     for y in 0..cli.text.len() { | ||||
|         let row = &cli.text[y]; | ||||
| 
 | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ pub type Offset = usize; | |||
| /// A grid containing codepage 437 characters.
 | ||||
| ///
 | ||||
| /// The encoding is currently not enforced.
 | ||||
| pub type Cp473Grid = PrimitiveGrid<u8>; | ||||
| pub type Cp437Grid = PrimitiveGrid<u8>; | ||||
| 
 | ||||
| /// A command to send to the display.
 | ||||
| #[derive(Debug, Clone, PartialEq)] | ||||
|  | @ -27,7 +27,7 @@ pub enum Command { | |||
|     ///     The library does not currently convert between UTF-8 and CP-437.
 | ||||
|     ///     Because Rust expects UTF-8 strings, it might be necessary to only send ASCII for now.
 | ||||
|     /// </div>
 | ||||
|     Cp437Data(Origin<Tiles>, Cp473Grid), | ||||
|     Cp437Data(Origin<Tiles>, Cp437Grid), | ||||
| 
 | ||||
|     /// Sets a window of pixels to the specified values
 | ||||
|     BitmapLinearWin(Origin<Pixels>, PixelGrid, CompressionCode), | ||||
|  | @ -276,7 +276,7 @@ impl TryFrom<Packet> for Command { | |||
|                 let Packet(_, payload) = packet; | ||||
|                 Ok(Command::Cp437Data( | ||||
|                     Origin::new(a as usize, b as usize), | ||||
|                     Cp473Grid::load(c as usize, d as usize, &payload), | ||||
|                     Cp437Grid::load(c as usize, d as usize, &payload), | ||||
|                 )) | ||||
|             } | ||||
|             CommandCode::CharBrightness => { | ||||
|  |  | |||
|  | @ -6,7 +6,7 @@ pub use bitvec; | |||
| use bitvec::prelude::{BitVec, Msb0}; | ||||
| 
 | ||||
| pub use crate::brightness::{Brightness, BrightnessGrid}; | ||||
| pub use crate::command::{Command, Cp473Grid, Offset}; | ||||
| pub use crate::command::{Command, Cp437Grid, Offset}; | ||||
| pub use crate::compression_code::CompressionCode; | ||||
| pub use crate::connection::Connection; | ||||
| pub use crate::data_ref::DataRef; | ||||
|  |  | |||
|  | @ -33,4 +33,4 @@ include = ["servicepoint"] | |||
| extra_bindings = ["servicepoint"] | ||||
| 
 | ||||
| [parse.expand] | ||||
| #all_features = true | ||||
| all_features = true | ||||
|  |  | |||
|  | @ -70,14 +70,18 @@ typedef uint16_t sp_CompressionCode; | |||
| #endif // __cplusplus
 | ||||
| 
 | ||||
| /**
 | ||||
|  * A fixed-size vector of bits | ||||
|  * A display brightness value, checked for correct value range | ||||
|  */ | ||||
| typedef struct sp_BitVec sp_BitVec; | ||||
| typedef struct sp_Brightness sp_Brightness; | ||||
| 
 | ||||
| /**
 | ||||
|  * A 2D grid of bytes | ||||
|  * Opaque struct needed for correct code generation. | ||||
|  */ | ||||
| typedef struct sp_ByteGrid sp_ByteGrid; | ||||
| typedef struct sp_CBitVec sp_CBitVec; | ||||
| 
 | ||||
| typedef struct sp_CBrightnessGrid sp_CBrightnessGrid; | ||||
| 
 | ||||
| typedef struct sp_CCp437Grid sp_CCp437Grid; | ||||
| 
 | ||||
| /**
 | ||||
|  * A command to send to the display. | ||||
|  | @ -99,6 +103,16 @@ typedef struct sp_Packet sp_Packet; | |||
|  */ | ||||
| typedef struct sp_PixelGrid sp_PixelGrid; | ||||
| 
 | ||||
| /**
 | ||||
|  * A 2D grid of bytes | ||||
|  */ | ||||
| typedef struct sp_PrimitiveGrid_Brightness sp_PrimitiveGrid_Brightness; | ||||
| 
 | ||||
| /**
 | ||||
|  * A 2D grid of bytes | ||||
|  */ | ||||
| typedef struct sp_PrimitiveGrid_u8 sp_PrimitiveGrid_u8; | ||||
| 
 | ||||
| /**
 | ||||
|  * Represents a span of memory (`&mut [u8]` ) as a struct usable by C code. | ||||
|  * | ||||
|  | @ -127,9 +141,20 @@ typedef struct sp_CByteSlice { | |||
| typedef size_t sp_Offset; | ||||
| 
 | ||||
| /**
 | ||||
|  * Type alias for documenting the meaning of the u16 in enum values | ||||
|  * A grid containing brightness values. | ||||
|  */ | ||||
| typedef uint8_t sp_Brightness; | ||||
| typedef struct sp_PrimitiveGrid_Brightness sp_BrightnessGrid; | ||||
| 
 | ||||
| /**
 | ||||
|  * A grid containing codepage 437 characters. | ||||
|  * | ||||
|  * The encoding is currently not enforced. | ||||
|  */ | ||||
| typedef struct sp_PrimitiveGrid_u8 sp_Cp437Grid; | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| #ifdef __cplusplus | ||||
| extern "C" { | ||||
|  | @ -147,7 +172,7 @@ extern "C" { | |||
|  * - the returned instance is freed in some way, either by using a consuming function or | ||||
|  *   by explicitly calling `sp_bit_vec_dealloc`. | ||||
|  */ | ||||
| struct sp_BitVec *sp_bit_vec_clone(const struct sp_BitVec *this_); | ||||
| struct sp_CBitVec *sp_bit_vec_clone(const struct sp_CBitVec *this_); | ||||
| 
 | ||||
| /**
 | ||||
|  * Deallocates a `BitVec`. | ||||
|  | @ -160,7 +185,7 @@ struct sp_BitVec *sp_bit_vec_clone(const struct sp_BitVec *this_); | |||
|  * - `this` is not used concurrently or after this call | ||||
|  * - `this` was not passed to another consuming function, e.g. to create a `Command` | ||||
|  */ | ||||
| void sp_bit_vec_dealloc(struct sp_BitVec *this_); | ||||
| void sp_bit_vec_dealloc(struct sp_CBitVec *this_); | ||||
| 
 | ||||
| /**
 | ||||
|  * Sets the value of all bits in the `BitVec`. | ||||
|  | @ -176,7 +201,7 @@ void sp_bit_vec_dealloc(struct sp_BitVec *this_); | |||
|  * - `this` points to a valid `BitVec` | ||||
|  * - `this` is not written to or read from concurrently | ||||
|  */ | ||||
| void sp_bit_vec_fill(struct sp_BitVec *this_, bool value); | ||||
| void sp_bit_vec_fill(struct sp_CBitVec *this_, bool value); | ||||
| 
 | ||||
| /**
 | ||||
|  * Gets the value of a bit from the `BitVec`. | ||||
|  | @ -199,7 +224,7 @@ void sp_bit_vec_fill(struct sp_BitVec *this_, bool value); | |||
|  * - `this` points to a valid `BitVec` | ||||
|  * - `this` is not written to concurrently | ||||
|  */ | ||||
| bool sp_bit_vec_get(const struct sp_BitVec *this_, size_t index); | ||||
| bool sp_bit_vec_get(const struct sp_CBitVec *this_, size_t index); | ||||
| 
 | ||||
| /**
 | ||||
|  * Returns true if length is 0. | ||||
|  | @ -210,7 +235,7 @@ bool sp_bit_vec_get(const struct sp_BitVec *this_, size_t index); | |||
|  * | ||||
|  * - `this` points to a valid `BitVec` | ||||
|  */ | ||||
| bool sp_bit_vec_is_empty(const struct sp_BitVec *this_); | ||||
| bool sp_bit_vec_is_empty(const struct sp_CBitVec *this_); | ||||
| 
 | ||||
| /**
 | ||||
|  * Gets the length of the `BitVec` in bits. | ||||
|  | @ -221,7 +246,7 @@ bool sp_bit_vec_is_empty(const struct sp_BitVec *this_); | |||
|  * | ||||
|  * - `this` points to a valid `BitVec` | ||||
|  */ | ||||
| size_t sp_bit_vec_len(const struct sp_BitVec *this_); | ||||
| size_t sp_bit_vec_len(const struct sp_CBitVec *this_); | ||||
| 
 | ||||
| /**
 | ||||
|  * Interpret the data as a series of bits and load then into a new `BitVec` instance. | ||||
|  | @ -235,8 +260,8 @@ size_t sp_bit_vec_len(const struct sp_BitVec *this_); | |||
|  * - the returned instance is freed in some way, either by using a consuming function or | ||||
|  *   by explicitly calling `sp_bit_vec_dealloc`. | ||||
|  */ | ||||
| struct sp_BitVec *sp_bit_vec_load(const uint8_t *data, | ||||
|                                   size_t data_length); | ||||
| struct sp_CBitVec *sp_bit_vec_load(const uint8_t *data, | ||||
|                                    size_t data_length); | ||||
| 
 | ||||
| /**
 | ||||
|  * Creates a new `BitVec` instance. | ||||
|  | @ -258,7 +283,7 @@ struct sp_BitVec *sp_bit_vec_load(const uint8_t *data, | |||
|  * - the returned instance is freed in some way, either by using a consuming function or | ||||
|  *   by explicitly calling `sp_bit_vec_dealloc`. | ||||
|  */ | ||||
| struct sp_BitVec *sp_bit_vec_new(size_t size); | ||||
| struct sp_CBitVec *sp_bit_vec_new(size_t size); | ||||
| 
 | ||||
| /**
 | ||||
|  * Sets the value of a bit in the `BitVec`. | ||||
|  | @ -282,7 +307,7 @@ struct sp_BitVec *sp_bit_vec_new(size_t size); | |||
|  * - `this` points to a valid `BitVec` | ||||
|  * - `this` is not written to or read from concurrently | ||||
|  */ | ||||
| bool sp_bit_vec_set(struct sp_BitVec *this_, size_t index, bool value); | ||||
| void sp_bit_vec_set(struct sp_CBitVec *this_, size_t index, bool value); | ||||
| 
 | ||||
| /**
 | ||||
|  * Gets an unsafe reference to the data of the `BitVec` instance. | ||||
|  | @ -295,37 +320,37 @@ bool sp_bit_vec_set(struct sp_BitVec *this_, size_t index, bool value); | |||
|  * - the returned memory range is never accessed after the passed `BitVec` has been freed | ||||
|  * - the returned memory range is never accessed concurrently, either via the `BitVec` or directly | ||||
|  */ | ||||
| struct sp_CByteSlice sp_bit_vec_unsafe_data_ref(struct sp_BitVec *this_); | ||||
| struct sp_CByteSlice sp_bit_vec_unsafe_data_ref(struct sp_CBitVec *this_); | ||||
| 
 | ||||
| /**
 | ||||
|  * Clones a `ByteGrid`. | ||||
|  * Clones a `BrightnessGrid`. | ||||
|  * | ||||
|  * # Safety | ||||
|  * | ||||
|  * The caller has to make sure that: | ||||
|  * | ||||
|  * - `this` points to a valid `ByteGrid` | ||||
|  * - `this` points to a valid `BrightnessGrid` | ||||
|  * - `this` is not written to concurrently | ||||
|  * - the returned instance is freed in some way, either by using a consuming function or | ||||
|  *   by explicitly calling `sp_byte_grid_dealloc`. | ||||
|  *   by explicitly calling `sp_brightness_grid_dealloc`. | ||||
|  */ | ||||
| struct sp_ByteGrid *sp_byte_grid_clone(const struct sp_ByteGrid *this_); | ||||
| struct sp_CBrightnessGrid *sp_brightness_grid_clone(const struct sp_CBrightnessGrid *this_); | ||||
| 
 | ||||
| /**
 | ||||
|  * Deallocates a `ByteGrid`. | ||||
|  * Deallocates a `BrightnessGrid`. | ||||
|  * | ||||
|  * # Safety | ||||
|  * | ||||
|  * The caller has to make sure that: | ||||
|  * | ||||
|  * - `this` points to a valid `ByteGrid` | ||||
|  * - `this` points to a valid `BrightnessGrid` | ||||
|  * - `this` is not used concurrently or after this call | ||||
|  * - `this` was not passed to another consuming function, e.g. to create a `Command` | ||||
|  */ | ||||
| void sp_byte_grid_dealloc(struct sp_ByteGrid *this_); | ||||
| void sp_brightness_grid_dealloc(struct sp_CBrightnessGrid *this_); | ||||
| 
 | ||||
| /**
 | ||||
|  * Sets the value of all cells in the `ByteGrid`. | ||||
|  * Sets the value of all cells in the `BrightnessGrid`. | ||||
|  * | ||||
|  * # Arguments | ||||
|  * | ||||
|  | @ -336,10 +361,10 @@ void sp_byte_grid_dealloc(struct sp_ByteGrid *this_); | |||
|  * | ||||
|  * The caller has to make sure that: | ||||
|  * | ||||
|  * - `this` points to a valid `ByteGrid` | ||||
|  * - `this` points to a valid `BrightnessGrid` | ||||
|  * - `this` is not written to or read from concurrently | ||||
|  */ | ||||
| void sp_byte_grid_fill(struct sp_ByteGrid *this_, uint8_t value); | ||||
| void sp_brightness_grid_fill(struct sp_CBrightnessGrid *this_, uint8_t value); | ||||
| 
 | ||||
| /**
 | ||||
|  * Gets the current value at the specified position. | ||||
|  | @ -357,13 +382,15 @@ void sp_byte_grid_fill(struct sp_ByteGrid *this_, uint8_t value); | |||
|  * | ||||
|  * The caller has to make sure that: | ||||
|  * | ||||
|  * - `this` points to a valid `ByteGrid` | ||||
|  * - `this` points to a valid `BrightnessGrid` | ||||
|  * - `this` is not written to concurrently | ||||
|  */ | ||||
| uint8_t sp_byte_grid_get(const struct sp_ByteGrid *this_, size_t x, size_t y); | ||||
| uint8_t sp_brightness_grid_get(const struct sp_CBrightnessGrid *this_, | ||||
|                                size_t x, | ||||
|                                size_t y); | ||||
| 
 | ||||
| /**
 | ||||
|  * Gets the height of the `ByteGrid` instance. | ||||
|  * Gets the height of the `BrightnessGrid` instance. | ||||
|  * | ||||
|  * # Arguments | ||||
|  * | ||||
|  | @ -373,12 +400,12 @@ uint8_t sp_byte_grid_get(const struct sp_ByteGrid *this_, size_t x, size_t y); | |||
|  * | ||||
|  * The caller has to make sure that: | ||||
|  * | ||||
|  * - `this` points to a valid `ByteGrid` | ||||
|  * - `this` points to a valid `BrightnessGrid` | ||||
|  */ | ||||
| size_t sp_byte_grid_height(const struct sp_ByteGrid *this_); | ||||
| size_t sp_brightness_grid_height(const struct sp_CBrightnessGrid *this_); | ||||
| 
 | ||||
| /**
 | ||||
|  * Loads a `ByteGrid` with the specified dimensions from the provided data. | ||||
|  * Loads a `BrightnessGrid` with the specified dimensions from the provided data. | ||||
|  * | ||||
|  * # Panics | ||||
|  * | ||||
|  | @ -391,30 +418,30 @@ size_t sp_byte_grid_height(const struct sp_ByteGrid *this_); | |||
|  * - `data` points to a valid memory location of at least `data_length` | ||||
|  *   bytes in size. | ||||
|  * - the returned instance is freed in some way, either by using a consuming function or | ||||
|  *   by explicitly calling `sp_byte_grid_dealloc`. | ||||
|  *   by explicitly calling `sp_brightness_grid_dealloc`. | ||||
|  */ | ||||
| struct sp_ByteGrid *sp_byte_grid_load(size_t width, | ||||
|                                       size_t height, | ||||
|                                       const uint8_t *data, | ||||
|                                       size_t data_length); | ||||
| struct sp_CBrightnessGrid *sp_brightness_grid_load(size_t width, | ||||
|                                                    size_t height, | ||||
|                                                    const uint8_t *data, | ||||
|                                                    size_t data_length); | ||||
| 
 | ||||
| /**
 | ||||
|  * Creates a new `ByteGrid` with the specified dimensions. | ||||
|  * Creates a new `BrightnessGrid` with the specified dimensions. | ||||
|  * | ||||
|  * returns: `ByteGrid` initialized to 0. | ||||
|  * returns: `BrightnessGrid` initialized to 0. | ||||
|  * | ||||
|  * # 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_byte_grid_dealloc`. | ||||
|  *   by explicitly calling `sp_brightness_grid_dealloc`. | ||||
|  */ | ||||
| struct sp_ByteGrid *sp_byte_grid_new(size_t width, | ||||
|                                      size_t height); | ||||
| struct sp_CBrightnessGrid *sp_brightness_grid_new(size_t width, | ||||
|                                                   size_t height); | ||||
| 
 | ||||
| /**
 | ||||
|  * Sets the value of the specified position in the `ByteGrid`. | ||||
|  * Sets the value of the specified position in the `BrightnessGrid`. | ||||
|  * | ||||
|  * # Arguments | ||||
|  * | ||||
|  | @ -435,26 +462,26 @@ struct sp_ByteGrid *sp_byte_grid_new(size_t width, | |||
|  * - `this` points to a valid `BitVec` | ||||
|  * - `this` is not written to or read from concurrently | ||||
|  */ | ||||
| void sp_byte_grid_set(struct sp_ByteGrid *this_, | ||||
|                       size_t x, | ||||
|                       size_t y, | ||||
|                       uint8_t value); | ||||
| void sp_brightness_grid_set(struct sp_CBrightnessGrid *this_, | ||||
|                             size_t x, | ||||
|                             size_t y, | ||||
|                             uint8_t value); | ||||
| 
 | ||||
| /**
 | ||||
|  * Gets an unsafe reference to the data of the `ByteGrid` instance. | ||||
|  * Gets an unsafe reference to the data of the `BrightnessGrid` instance. | ||||
|  * | ||||
|  * ## Safety | ||||
|  * | ||||
|  * The caller has to make sure that: | ||||
|  * | ||||
|  * - `this` points to a valid `ByteGrid` | ||||
|  * - the returned memory range is never accessed after the passed `ByteGrid` has been freed | ||||
|  * - the returned memory range is never accessed concurrently, either via the `ByteGrid` or directly | ||||
|  * - `this` points to a valid `BrightnessGrid` | ||||
|  * - the returned memory range is never accessed after the passed `BrightnessGrid` has been freed | ||||
|  * - the returned memory range is never accessed concurrently, either via the `BrightnessGrid` or directly | ||||
|  */ | ||||
| struct sp_CByteSlice sp_byte_grid_unsafe_data_ref(struct sp_ByteGrid *this_); | ||||
| struct sp_CByteSlice sp_brightness_grid_unsafe_data_ref(struct sp_CBrightnessGrid *this_); | ||||
| 
 | ||||
| /**
 | ||||
|  * Gets the width of the `ByteGrid` instance. | ||||
|  * Gets the width of the `BrightnessGrid` instance. | ||||
|  * | ||||
|  * # Arguments | ||||
|  * | ||||
|  | @ -464,9 +491,9 @@ struct sp_CByteSlice sp_byte_grid_unsafe_data_ref(struct sp_ByteGrid *this_); | |||
|  * | ||||
|  * The caller has to make sure that: | ||||
|  * | ||||
|  * - `this` points to a valid `ByteGrid` | ||||
|  * - `this` points to a valid `BrightnessGrid` | ||||
|  */ | ||||
| size_t sp_byte_grid_width(const struct sp_ByteGrid *this_); | ||||
| size_t sp_brightness_grid_width(const struct sp_CBrightnessGrid *this_); | ||||
| 
 | ||||
| /**
 | ||||
|  * Allocates a new `Command::BitmapLinear` instance. | ||||
|  | @ -483,7 +510,7 @@ size_t sp_byte_grid_width(const struct sp_ByteGrid *this_); | |||
|  *   by explicitly calling `sp_command_dealloc`. | ||||
|  */ | ||||
| struct sp_Command *sp_command_bitmap_linear(sp_Offset offset, | ||||
|                                             struct sp_BitVec *bit_vec, | ||||
|                                             struct sp_CBitVec *bit_vec, | ||||
|                                             sp_CompressionCode compression); | ||||
| 
 | ||||
| /**
 | ||||
|  | @ -501,7 +528,7 @@ struct sp_Command *sp_command_bitmap_linear(sp_Offset offset, | |||
|  *   by explicitly calling `sp_command_dealloc`. | ||||
|  */ | ||||
| struct sp_Command *sp_command_bitmap_linear_and(sp_Offset offset, | ||||
|                                                 struct sp_BitVec *bit_vec, | ||||
|                                                 struct sp_CBitVec *bit_vec, | ||||
|                                                 sp_CompressionCode compression); | ||||
| 
 | ||||
| /**
 | ||||
|  | @ -519,7 +546,7 @@ struct sp_Command *sp_command_bitmap_linear_and(sp_Offset offset, | |||
|  *   by explicitly calling `sp_command_dealloc`. | ||||
|  */ | ||||
| struct sp_Command *sp_command_bitmap_linear_or(sp_Offset offset, | ||||
|                                                struct sp_BitVec *bit_vec, | ||||
|                                                struct sp_CBitVec *bit_vec, | ||||
|                                                sp_CompressionCode compression); | ||||
| 
 | ||||
| /**
 | ||||
|  | @ -556,11 +583,16 @@ struct sp_Command *sp_command_bitmap_linear_win(size_t x, | |||
|  *   by explicitly calling `sp_command_dealloc`. | ||||
|  */ | ||||
| struct sp_Command *sp_command_bitmap_linear_xor(sp_Offset offset, | ||||
|                                                 struct sp_BitVec *bit_vec, | ||||
|                                                 struct sp_CBitVec *bit_vec, | ||||
|                                                 sp_CompressionCode compression); | ||||
| 
 | ||||
| /**
 | ||||
|  * Allocates a new `Command::Brightness` instance. | ||||
|  * Allocates a new `Command::Brightness` instance for setting the brightness of all tiles to the | ||||
|  * same value. | ||||
|  * | ||||
|  * # Panics | ||||
|  * | ||||
|  * - When the provided brightness value is out of range (0-11). | ||||
|  * | ||||
|  * # Safety | ||||
|  * | ||||
|  | @ -569,7 +601,7 @@ struct sp_Command *sp_command_bitmap_linear_xor(sp_Offset offset, | |||
|  * - the returned `Command` instance is freed in some way, either by using a consuming function or | ||||
|  *   by explicitly calling `sp_command_dealloc`. | ||||
|  */ | ||||
| struct sp_Command *sp_command_brightness(sp_Brightness brightness); | ||||
| struct sp_Command *sp_command_brightness(uint8_t brightness); | ||||
| 
 | ||||
| /**
 | ||||
|  * Allocates a new `Command::CharBrightness` instance. | ||||
|  | @ -586,7 +618,7 @@ struct sp_Command *sp_command_brightness(sp_Brightness brightness); | |||
|  */ | ||||
| struct sp_Command *sp_command_char_brightness(size_t x, | ||||
|                                               size_t y, | ||||
|                                               struct sp_ByteGrid *byte_grid); | ||||
|                                               sp_BrightnessGrid *byte_grid); | ||||
| 
 | ||||
| /**
 | ||||
|  * Allocates a new `Command::Clear` instance. | ||||
|  | @ -629,7 +661,7 @@ struct sp_Command *sp_command_clone(const struct sp_Command *original); | |||
|  */ | ||||
| struct sp_Command *sp_command_cp437_data(size_t x, | ||||
|                                          size_t y, | ||||
|                                          struct sp_ByteGrid *byte_grid); | ||||
|                                          sp_Cp437Grid *byte_grid); | ||||
| 
 | ||||
| /**
 | ||||
|  * Deallocates a `Command`. | ||||
|  | @ -732,6 +764,179 @@ struct sp_Connection *sp_connection_open(const char *host); | |||
| bool sp_connection_send(const struct sp_Connection *connection, | ||||
|                         struct sp_Packet *packet); | ||||
| 
 | ||||
| /**
 | ||||
|  * Clones a `Cp437Grid`. | ||||
|  * | ||||
|  * # Safety | ||||
|  * | ||||
|  * The caller has to make sure that: | ||||
|  * | ||||
|  * - `this` points to a valid `Cp437Grid` | ||||
|  * - `this` is not written to concurrently | ||||
|  * - the returned instance is freed in some way, either by using a consuming function or | ||||
|  *   by explicitly calling `sp_cp437_grid_dealloc`. | ||||
|  */ | ||||
| struct sp_CCp437Grid *sp_cp437_grid_clone(const struct sp_CCp437Grid *this_); | ||||
| 
 | ||||
| /**
 | ||||
|  * Deallocates a `Cp437Grid`. | ||||
|  * | ||||
|  * # Safety | ||||
|  * | ||||
|  * The caller has to make sure that: | ||||
|  * | ||||
|  * - `this` points to a valid `Cp437Grid` | ||||
|  * - `this` is not used concurrently or after this call | ||||
|  * - `this` was not passed to another consuming function, e.g. to create a `Command` | ||||
|  */ | ||||
| void sp_cp437_grid_dealloc(struct sp_CCp437Grid *this_); | ||||
| 
 | ||||
| /**
 | ||||
|  * Sets the value of all cells in the `Cp437Grid`. | ||||
|  * | ||||
|  * # Arguments | ||||
|  * | ||||
|  * * `this`: instance to write to | ||||
|  * * `value`: the value to set all cells to | ||||
|  * | ||||
|  * # Safety | ||||
|  * | ||||
|  * The caller has to make sure that: | ||||
|  * | ||||
|  * - `this` points to a valid `Cp437Grid` | ||||
|  * - `this` is not written to or read from concurrently | ||||
|  */ | ||||
| void sp_cp437_grid_fill(struct sp_CCp437Grid *this_, uint8_t value); | ||||
| 
 | ||||
| /**
 | ||||
|  * Gets the current value at the specified position. | ||||
|  * | ||||
|  * # Arguments | ||||
|  * | ||||
|  * * `this`: instance to read from | ||||
|  * * `x` and `y`: position of the cell to read | ||||
|  * | ||||
|  * # Panics | ||||
|  * | ||||
|  * When accessing `x` or `y` out of bounds. | ||||
|  * | ||||
|  * # Safety | ||||
|  * | ||||
|  * The caller has to make sure that: | ||||
|  * | ||||
|  * - `this` points to a valid `Cp437Grid` | ||||
|  * - `this` is not written to concurrently | ||||
|  */ | ||||
| uint8_t sp_cp437_grid_get(const struct sp_CCp437Grid *this_, | ||||
|                           size_t x, | ||||
|                           size_t y); | ||||
| 
 | ||||
| /**
 | ||||
|  * Gets the height of the `Cp437Grid` instance. | ||||
|  * | ||||
|  * # Arguments | ||||
|  * | ||||
|  * * `this`: instance to read from | ||||
|  * | ||||
|  * # Safety | ||||
|  * | ||||
|  * The caller has to make sure that: | ||||
|  * | ||||
|  * - `this` points to a valid `Cp437Grid` | ||||
|  */ | ||||
| size_t sp_cp437_grid_height(const struct sp_CCp437Grid *this_); | ||||
| 
 | ||||
| /**
 | ||||
|  * Loads a `Cp437Grid` with the specified dimensions from the provided data. | ||||
|  * | ||||
|  * # Panics | ||||
|  * | ||||
|  * When the provided `data_length` is not sufficient for the `height` and `width` | ||||
|  * | ||||
|  * # Safety | ||||
|  * | ||||
|  * The caller has to make sure that: | ||||
|  * | ||||
|  * - `data` points to a valid memory location of at least `data_length` | ||||
|  *   bytes in size. | ||||
|  * - the returned instance is freed in some way, either by using a consuming function or | ||||
|  *   by explicitly calling `sp_cp437_grid_dealloc`. | ||||
|  */ | ||||
| struct sp_CCp437Grid *sp_cp437_grid_load(size_t width, | ||||
|                                          size_t height, | ||||
|                                          const uint8_t *data, | ||||
|                                          size_t data_length); | ||||
| 
 | ||||
| /**
 | ||||
|  * Creates a new `Cp437Grid` with the specified dimensions. | ||||
|  * | ||||
|  * returns: `Cp437Grid` initialized to 0. | ||||
|  * | ||||
|  * # 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_cp437_grid_dealloc`. | ||||
|  */ | ||||
| struct sp_CCp437Grid *sp_cp437_grid_new(size_t width, | ||||
|                                         size_t height); | ||||
| 
 | ||||
| /**
 | ||||
|  * Sets the value of the specified position in the `Cp437Grid`. | ||||
|  * | ||||
|  * # Arguments | ||||
|  * | ||||
|  * * `this`: instance to write to | ||||
|  * * `x` and `y`: position of the cell | ||||
|  * * `value`: the value to write to the cell | ||||
|  * | ||||
|  * returns: old value of the cell | ||||
|  * | ||||
|  * # Panics | ||||
|  * | ||||
|  * When accessing `x` or `y` out of bounds. | ||||
|  * | ||||
|  * # Safety | ||||
|  * | ||||
|  * The caller has to make sure that: | ||||
|  * | ||||
|  * - `this` points to a valid `BitVec` | ||||
|  * - `this` is not written to or read from concurrently | ||||
|  */ | ||||
| void sp_cp437_grid_set(struct sp_CCp437Grid *this_, | ||||
|                        size_t x, | ||||
|                        size_t y, | ||||
|                        uint8_t value); | ||||
| 
 | ||||
| /**
 | ||||
|  * Gets an unsafe reference to the data of the `Cp437Grid` instance. | ||||
|  * | ||||
|  * ## Safety | ||||
|  * | ||||
|  * The caller has to make sure that: | ||||
|  * | ||||
|  * - `this` points to a valid `Cp437Grid` | ||||
|  * - the returned memory range is never accessed after the passed `Cp437Grid` has been freed | ||||
|  * - the returned memory range is never accessed concurrently, either via the `Cp437Grid` or directly | ||||
|  */ | ||||
| struct sp_CByteSlice sp_cp437_grid_unsafe_data_ref(struct sp_CCp437Grid *this_); | ||||
| 
 | ||||
| /**
 | ||||
|  * Gets the width of the `Cp437Grid` instance. | ||||
|  * | ||||
|  * # Arguments | ||||
|  * | ||||
|  * * `this`: instance to read from | ||||
|  * | ||||
|  * # Safety | ||||
|  * | ||||
|  * The caller has to make sure that: | ||||
|  * | ||||
|  * - `this` points to a valid `Cp437Grid` | ||||
|  */ | ||||
| size_t sp_cp437_grid_width(const struct sp_CCp437Grid *this_); | ||||
| 
 | ||||
| /**
 | ||||
|  * Deallocates a `Packet`. | ||||
|  * | ||||
|  |  | |||
							
								
								
									
										222
									
								
								crates/servicepoint_binding_c/src/brightness_grid.rs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										222
									
								
								crates/servicepoint_binding_c/src/brightness_grid.rs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,222 @@ | |||
| //! C functions for interacting with `BrightnessGrid`s
 | ||||
| //!
 | ||||
| //! prefix `sp_brightness_grid_`
 | ||||
| 
 | ||||
| use std::intrinsics::transmute; | ||||
| use servicepoint::{BrightnessGrid, DataRef, Grid, PrimitiveGrid, Brightness}; | ||||
| 
 | ||||
| use crate::c_slice::CByteSlice; | ||||
| 
 | ||||
| /// C-wrapper for grid containing brightness values.
 | ||||
| #[derive(Clone)] | ||||
| pub struct CBrightnessGrid(pub(crate) BrightnessGrid); | ||||
| 
 | ||||
| /// Creates a new `BrightnessGrid` with the specified dimensions.
 | ||||
| ///
 | ||||
| /// returns: `BrightnessGrid` initialized to 0.
 | ||||
| ///
 | ||||
| /// # 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_brightness_grid_dealloc`.
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_brightness_grid_new( | ||||
|     width: usize, | ||||
|     height: usize, | ||||
| ) -> *mut CBrightnessGrid { | ||||
|     Box::into_raw(Box::new(CBrightnessGrid(BrightnessGrid::new(width, height)))) | ||||
| } | ||||
| 
 | ||||
| /// Loads a `BrightnessGrid` with the specified dimensions from the provided data.
 | ||||
| ///
 | ||||
| /// # Panics
 | ||||
| ///
 | ||||
| /// When the provided `data_length` is not sufficient for the `height` and `width`
 | ||||
| ///
 | ||||
| /// # Safety
 | ||||
| ///
 | ||||
| /// The caller has to make sure that:
 | ||||
| ///
 | ||||
| /// - `data` points to a valid memory location of at least `data_length`
 | ||||
| ///   bytes in size.
 | ||||
| /// - the returned instance is freed in some way, either by using a consuming function or
 | ||||
| ///   by explicitly calling `sp_brightness_grid_dealloc`.
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_brightness_grid_load( | ||||
|     width: usize, | ||||
|     height: usize, | ||||
|     data: *const u8, | ||||
|     data_length: usize, | ||||
| ) -> *mut CBrightnessGrid { | ||||
|     let data = std::slice::from_raw_parts(data, data_length); | ||||
|     let grid = PrimitiveGrid::load(width, height, data); | ||||
|     let grid = BrightnessGrid::try_from(grid) | ||||
|         .expect("invalid brightness value"); | ||||
|     Box::into_raw(Box::new(CBrightnessGrid(grid))) | ||||
| } | ||||
| 
 | ||||
| /// Clones a `BrightnessGrid`.
 | ||||
| ///
 | ||||
| /// # Safety
 | ||||
| ///
 | ||||
| /// The caller has to make sure that:
 | ||||
| ///
 | ||||
| /// - `this` points to a valid `BrightnessGrid`
 | ||||
| /// - `this` is not written to concurrently
 | ||||
| /// - the returned instance is freed in some way, either by using a consuming function or
 | ||||
| ///   by explicitly calling `sp_brightness_grid_dealloc`.
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_brightness_grid_clone( | ||||
|     this: *const CBrightnessGrid, | ||||
| ) -> *mut CBrightnessGrid { | ||||
|     Box::into_raw(Box::new((*this).clone())) | ||||
| } | ||||
| 
 | ||||
| /// Deallocates a `BrightnessGrid`.
 | ||||
| ///
 | ||||
| /// # Safety
 | ||||
| ///
 | ||||
| /// The caller has to make sure that:
 | ||||
| ///
 | ||||
| /// - `this` points to a valid `BrightnessGrid`
 | ||||
| /// - `this` is not used concurrently or after this call
 | ||||
| /// - `this` was not passed to another consuming function, e.g. to create a `Command`
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_brightness_grid_dealloc(this: *mut CBrightnessGrid) { | ||||
|     _ = Box::from_raw(this); | ||||
| } | ||||
| 
 | ||||
| /// Gets the current value at the specified position.
 | ||||
| ///
 | ||||
| /// # Arguments
 | ||||
| ///
 | ||||
| /// * `this`: instance to read from
 | ||||
| /// * `x` and `y`: position of the cell to read
 | ||||
| ///
 | ||||
| /// # Panics
 | ||||
| ///
 | ||||
| /// When accessing `x` or `y` out of bounds.
 | ||||
| ///
 | ||||
| /// # Safety
 | ||||
| ///
 | ||||
| /// The caller has to make sure that:
 | ||||
| ///
 | ||||
| /// - `this` points to a valid `BrightnessGrid`
 | ||||
| /// - `this` is not written to concurrently
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_brightness_grid_get( | ||||
|     this: *const CBrightnessGrid, | ||||
|     x: usize, | ||||
|     y: usize, | ||||
| ) -> u8 { | ||||
|     (*this).0.get(x, y).into() | ||||
| } | ||||
| 
 | ||||
| /// Sets the value of the specified position in the `BrightnessGrid`.
 | ||||
| ///
 | ||||
| /// # Arguments
 | ||||
| ///
 | ||||
| /// * `this`: instance to write to
 | ||||
| /// * `x` and `y`: position of the cell
 | ||||
| /// * `value`: the value to write to the cell
 | ||||
| ///
 | ||||
| /// returns: old value of the cell
 | ||||
| ///
 | ||||
| /// # Panics
 | ||||
| ///
 | ||||
| /// When accessing `x` or `y` out of bounds.
 | ||||
| ///
 | ||||
| /// # Safety
 | ||||
| ///
 | ||||
| /// The caller has to make sure that:
 | ||||
| ///
 | ||||
| /// - `this` points to a valid `BitVec`
 | ||||
| /// - `this` is not written to or read from concurrently
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_brightness_grid_set( | ||||
|     this: *mut CBrightnessGrid, | ||||
|     x: usize, | ||||
|     y: usize, | ||||
|     value: u8, | ||||
| ) { | ||||
|     let brightness = Brightness::try_from(value) | ||||
|         .expect("invalid brightness value"); | ||||
|     (*this).0.set(x, y, brightness); | ||||
| } | ||||
| 
 | ||||
| /// Sets the value of all cells in the `BrightnessGrid`.
 | ||||
| ///
 | ||||
| /// # Arguments
 | ||||
| ///
 | ||||
| /// * `this`: instance to write to
 | ||||
| /// * `value`: the value to set all cells to
 | ||||
| ///
 | ||||
| /// # Safety
 | ||||
| ///
 | ||||
| /// The caller has to make sure that:
 | ||||
| ///
 | ||||
| /// - `this` points to a valid `BrightnessGrid`
 | ||||
| /// - `this` is not written to or read from concurrently
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_brightness_grid_fill(this: *mut CBrightnessGrid, value: u8) { | ||||
|     let brightness = Brightness::try_from(value) | ||||
|         .expect("invalid brightness value"); | ||||
|     (*this).0.fill(brightness); | ||||
| } | ||||
| 
 | ||||
| /// Gets the width of the `BrightnessGrid` instance.
 | ||||
| ///
 | ||||
| /// # Arguments
 | ||||
| ///
 | ||||
| /// * `this`: instance to read from
 | ||||
| ///
 | ||||
| /// # Safety
 | ||||
| ///
 | ||||
| /// The caller has to make sure that:
 | ||||
| ///
 | ||||
| /// - `this` points to a valid `BrightnessGrid`
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_brightness_grid_width(this: *const CBrightnessGrid) -> usize { | ||||
|     (*this).0.width() | ||||
| } | ||||
| 
 | ||||
| /// Gets the height of the `BrightnessGrid` instance.
 | ||||
| ///
 | ||||
| /// # Arguments
 | ||||
| ///
 | ||||
| /// * `this`: instance to read from
 | ||||
| ///
 | ||||
| /// # Safety
 | ||||
| ///
 | ||||
| /// The caller has to make sure that:
 | ||||
| ///
 | ||||
| /// - `this` points to a valid `BrightnessGrid`
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_brightness_grid_height(this: *const CBrightnessGrid) -> usize { | ||||
|     (*this).0.height() | ||||
| } | ||||
| 
 | ||||
| /// Gets an unsafe reference to the data of the `BrightnessGrid` instance.
 | ||||
| ///
 | ||||
| /// ## Safety
 | ||||
| ///
 | ||||
| /// The caller has to make sure that:
 | ||||
| ///
 | ||||
| /// - `this` points to a valid `BrightnessGrid`
 | ||||
| /// - the returned memory range is never accessed after the passed `BrightnessGrid` has been freed
 | ||||
| /// - the returned memory range is never accessed concurrently, either via the `BrightnessGrid` or directly
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_brightness_grid_unsafe_data_ref( | ||||
|     this: *mut CBrightnessGrid, | ||||
| ) -> CByteSlice { | ||||
|     assert_eq!(std::mem::size_of::<Brightness>(), 1); | ||||
| 
 | ||||
|     let data = (*this).0.data_ref_mut(); | ||||
|     let data: &mut [u8] = transmute(data); | ||||
|     CByteSlice { | ||||
|         start: data.as_mut_ptr_range().start, | ||||
|         length: data.len(), | ||||
|     } | ||||
| } | ||||
|  | @ -5,11 +5,13 @@ | |||
| use std::ptr::null_mut; | ||||
| 
 | ||||
| use servicepoint::{ | ||||
|     Brightness, BrightnessGrid, Command, CompressionCode, Cp473Grid, Offset, | ||||
|     Brightness, Command, CompressionCode, Offset, | ||||
|     Origin, Packet, PixelGrid, | ||||
| }; | ||||
| 
 | ||||
| use crate::bit_vec::CBitVec; | ||||
| use crate::brightness_grid::CBrightnessGrid; | ||||
| use crate::cp437_grid::CCp437Grid; | ||||
| 
 | ||||
| /// Tries to turn a `Packet` into a `Command`. The packet is deallocated in the process.
 | ||||
| ///
 | ||||
|  | @ -126,12 +128,12 @@ pub unsafe extern "C" fn sp_command_brightness(brightness: u8) -> *mut Command { | |||
| pub unsafe extern "C" fn sp_command_char_brightness( | ||||
|     x: usize, | ||||
|     y: usize, | ||||
|     byte_grid: *mut BrightnessGrid, | ||||
|     byte_grid: *mut CBrightnessGrid, | ||||
| ) -> *mut Command { | ||||
|     let byte_grid = *Box::from_raw(byte_grid); | ||||
|     Box::into_raw(Box::new(Command::CharBrightness( | ||||
|         Origin::new(x, y), | ||||
|         byte_grid, | ||||
|         byte_grid.0, | ||||
|     ))) | ||||
| } | ||||
| 
 | ||||
|  | @ -254,10 +256,10 @@ pub unsafe extern "C" fn sp_command_bitmap_linear_xor( | |||
| pub unsafe extern "C" fn sp_command_cp437_data( | ||||
|     x: usize, | ||||
|     y: usize, | ||||
|     byte_grid: *mut Cp473Grid, | ||||
|     byte_grid: *mut CCp437Grid, | ||||
| ) -> *mut Command { | ||||
|     let byte_grid = *Box::from_raw(byte_grid); | ||||
|     Box::into_raw(Box::new(Command::Cp437Data(Origin::new(x, y), byte_grid))) | ||||
|     Box::into_raw(Box::new(Command::Cp437Data(Origin::new(x, y), byte_grid.0))) | ||||
| } | ||||
| 
 | ||||
| /// Allocates a new `Command::BitmapLinearWin` instance.
 | ||||
|  |  | |||
|  | @ -1,32 +1,36 @@ | |||
| //! C functions for interacting with `ByteGrid`s
 | ||||
| //! C functions for interacting with `Cp437Grid`s
 | ||||
| //!
 | ||||
| //! prefix `sp_byte_grid_`
 | ||||
| //! prefix `sp_cp437_grid_`
 | ||||
| 
 | ||||
| use servicepoint::{DataRef, Grid, PrimitiveGrid}; | ||||
| use servicepoint::{Cp437Grid, DataRef, Grid}; | ||||
| 
 | ||||
| use crate::c_slice::CByteSlice; | ||||
| 
 | ||||
| pub type ByteGrid = PrimitiveGrid<u8>; | ||||
| 
 | ||||
| /// Creates a new `ByteGrid` with the specified dimensions.
 | ||||
| /// A C-wrapper for grid containing codepage 437 characters.
 | ||||
| ///
 | ||||
| /// returns: `ByteGrid` initialized to 0.
 | ||||
| /// The encoding is currently not enforced.
 | ||||
| #[derive(Clone)] | ||||
| pub struct CCp437Grid(pub(crate) Cp437Grid); | ||||
| 
 | ||||
| /// Creates a new `Cp437Grid` with the specified dimensions.
 | ||||
| ///
 | ||||
| /// returns: `Cp437Grid` initialized to 0.
 | ||||
| ///
 | ||||
| /// # 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_byte_grid_dealloc`.
 | ||||
| ///   by explicitly calling `sp_cp437_grid_dealloc`.
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_byte_grid_new( | ||||
| pub unsafe extern "C" fn sp_cp437_grid_new( | ||||
|     width: usize, | ||||
|     height: usize, | ||||
| ) -> *mut ByteGrid { | ||||
|     Box::into_raw(Box::new(ByteGrid::new(width, height))) | ||||
| ) -> *mut CCp437Grid { | ||||
|     Box::into_raw(Box::new(CCp437Grid(Cp437Grid::new(width, height)))) | ||||
| } | ||||
| 
 | ||||
| /// Loads a `ByteGrid` with the specified dimensions from the provided data.
 | ||||
| /// Loads a `Cp437Grid` with the specified dimensions from the provided data.
 | ||||
| ///
 | ||||
| /// # Panics
 | ||||
| ///
 | ||||
|  | @ -39,46 +43,46 @@ pub unsafe extern "C" fn sp_byte_grid_new( | |||
| /// - `data` points to a valid memory location of at least `data_length`
 | ||||
| ///   bytes in size.
 | ||||
| /// - the returned instance is freed in some way, either by using a consuming function or
 | ||||
| ///   by explicitly calling `sp_byte_grid_dealloc`.
 | ||||
| ///   by explicitly calling `sp_cp437_grid_dealloc`.
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_byte_grid_load( | ||||
| pub unsafe extern "C" fn sp_cp437_grid_load( | ||||
|     width: usize, | ||||
|     height: usize, | ||||
|     data: *const u8, | ||||
|     data_length: usize, | ||||
| ) -> *mut ByteGrid { | ||||
| ) -> *mut CCp437Grid { | ||||
|     let data = std::slice::from_raw_parts(data, data_length); | ||||
|     Box::into_raw(Box::new(ByteGrid::load(width, height, data))) | ||||
|     Box::into_raw(Box::new(CCp437Grid(Cp437Grid::load(width, height, data)))) | ||||
| } | ||||
| 
 | ||||
| /// Clones a `ByteGrid`.
 | ||||
| /// Clones a `Cp437Grid`.
 | ||||
| ///
 | ||||
| /// # Safety
 | ||||
| ///
 | ||||
| /// The caller has to make sure that:
 | ||||
| ///
 | ||||
| /// - `this` points to a valid `ByteGrid`
 | ||||
| /// - `this` points to a valid `Cp437Grid`
 | ||||
| /// - `this` is not written to concurrently
 | ||||
| /// - the returned instance is freed in some way, either by using a consuming function or
 | ||||
| ///   by explicitly calling `sp_byte_grid_dealloc`.
 | ||||
| ///   by explicitly calling `sp_cp437_grid_dealloc`.
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_byte_grid_clone( | ||||
|     this: *const ByteGrid, | ||||
| ) -> *mut ByteGrid { | ||||
| pub unsafe extern "C" fn sp_cp437_grid_clone( | ||||
|     this: *const CCp437Grid, | ||||
| ) -> *mut CCp437Grid { | ||||
|     Box::into_raw(Box::new((*this).clone())) | ||||
| } | ||||
| 
 | ||||
| /// Deallocates a `ByteGrid`.
 | ||||
| /// Deallocates a `Cp437Grid`.
 | ||||
| ///
 | ||||
| /// # Safety
 | ||||
| ///
 | ||||
| /// The caller has to make sure that:
 | ||||
| ///
 | ||||
| /// - `this` points to a valid `ByteGrid`
 | ||||
| /// - `this` points to a valid `Cp437Grid`
 | ||||
| /// - `this` is not used concurrently or after this call
 | ||||
| /// - `this` was not passed to another consuming function, e.g. to create a `Command`
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_byte_grid_dealloc(this: *mut ByteGrid) { | ||||
| pub unsafe extern "C" fn sp_cp437_grid_dealloc(this: *mut CCp437Grid) { | ||||
|     _ = Box::from_raw(this); | ||||
| } | ||||
| 
 | ||||
|  | @ -97,18 +101,18 @@ pub unsafe extern "C" fn sp_byte_grid_dealloc(this: *mut ByteGrid) { | |||
| ///
 | ||||
| /// The caller has to make sure that:
 | ||||
| ///
 | ||||
| /// - `this` points to a valid `ByteGrid`
 | ||||
| /// - `this` points to a valid `Cp437Grid`
 | ||||
| /// - `this` is not written to concurrently
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_byte_grid_get( | ||||
|     this: *const ByteGrid, | ||||
| pub unsafe extern "C" fn sp_cp437_grid_get( | ||||
|     this: *const CCp437Grid, | ||||
|     x: usize, | ||||
|     y: usize, | ||||
| ) -> u8 { | ||||
|     (*this).get(x, y) | ||||
|     (*this).0.get(x, y) | ||||
| } | ||||
| 
 | ||||
| /// Sets the value of the specified position in the `ByteGrid`.
 | ||||
| /// Sets the value of the specified position in the `Cp437Grid`.
 | ||||
| ///
 | ||||
| /// # Arguments
 | ||||
| ///
 | ||||
|  | @ -129,16 +133,16 @@ pub unsafe extern "C" fn sp_byte_grid_get( | |||
| /// - `this` points to a valid `BitVec`
 | ||||
| /// - `this` is not written to or read from concurrently
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_byte_grid_set( | ||||
|     this: *mut ByteGrid, | ||||
| pub unsafe extern "C" fn sp_cp437_grid_set( | ||||
|     this: *mut CCp437Grid, | ||||
|     x: usize, | ||||
|     y: usize, | ||||
|     value: u8, | ||||
| ) { | ||||
|     (*this).set(x, y, value); | ||||
|     (*this).0.set(x, y, value); | ||||
| } | ||||
| 
 | ||||
| /// Sets the value of all cells in the `ByteGrid`.
 | ||||
| /// Sets the value of all cells in the `Cp437Grid`.
 | ||||
| ///
 | ||||
| /// # Arguments
 | ||||
| ///
 | ||||
|  | @ -149,14 +153,14 @@ pub unsafe extern "C" fn sp_byte_grid_set( | |||
| ///
 | ||||
| /// The caller has to make sure that:
 | ||||
| ///
 | ||||
| /// - `this` points to a valid `ByteGrid`
 | ||||
| /// - `this` points to a valid `Cp437Grid`
 | ||||
| /// - `this` is not written to or read from concurrently
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_byte_grid_fill(this: *mut ByteGrid, value: u8) { | ||||
|     (*this).fill(value); | ||||
| pub unsafe extern "C" fn sp_cp437_grid_fill(this: *mut CCp437Grid, value: u8) { | ||||
|     (*this).0.fill(value); | ||||
| } | ||||
| 
 | ||||
| /// Gets the width of the `ByteGrid` instance.
 | ||||
| /// Gets the width of the `Cp437Grid` instance.
 | ||||
| ///
 | ||||
| /// # Arguments
 | ||||
| ///
 | ||||
|  | @ -166,13 +170,13 @@ pub unsafe extern "C" fn sp_byte_grid_fill(this: *mut ByteGrid, value: u8) { | |||
| ///
 | ||||
| /// The caller has to make sure that:
 | ||||
| ///
 | ||||
| /// - `this` points to a valid `ByteGrid`
 | ||||
| /// - `this` points to a valid `Cp437Grid`
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_byte_grid_width(this: *const ByteGrid) -> usize { | ||||
|     (*this).width() | ||||
| pub unsafe extern "C" fn sp_cp437_grid_width(this: *const CCp437Grid) -> usize { | ||||
|     (*this).0.width() | ||||
| } | ||||
| 
 | ||||
| /// Gets the height of the `ByteGrid` instance.
 | ||||
| /// Gets the height of the `Cp437Grid` instance.
 | ||||
| ///
 | ||||
| /// # Arguments
 | ||||
| ///
 | ||||
|  | @ -182,26 +186,26 @@ pub unsafe extern "C" fn sp_byte_grid_width(this: *const ByteGrid) -> usize { | |||
| ///
 | ||||
| /// The caller has to make sure that:
 | ||||
| ///
 | ||||
| /// - `this` points to a valid `ByteGrid`
 | ||||
| /// - `this` points to a valid `Cp437Grid`
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_byte_grid_height(this: *const ByteGrid) -> usize { | ||||
|     (*this).height() | ||||
| pub unsafe extern "C" fn sp_cp437_grid_height(this: *const CCp437Grid) -> usize { | ||||
|     (*this).0.height() | ||||
| } | ||||
| 
 | ||||
| /// Gets an unsafe reference to the data of the `ByteGrid` instance.
 | ||||
| /// Gets an unsafe reference to the data of the `Cp437Grid` instance.
 | ||||
| ///
 | ||||
| /// ## Safety
 | ||||
| ///
 | ||||
| /// The caller has to make sure that:
 | ||||
| ///
 | ||||
| /// - `this` points to a valid `ByteGrid`
 | ||||
| /// - the returned memory range is never accessed after the passed `ByteGrid` has been freed
 | ||||
| /// - the returned memory range is never accessed concurrently, either via the `ByteGrid` or directly
 | ||||
| /// - `this` points to a valid `Cp437Grid`
 | ||||
| /// - the returned memory range is never accessed after the passed `Cp437Grid` has been freed
 | ||||
| /// - the returned memory range is never accessed concurrently, either via the `Cp437Grid` or directly
 | ||||
| #[no_mangle] | ||||
| pub unsafe extern "C" fn sp_byte_grid_unsafe_data_ref( | ||||
|     this: *mut ByteGrid, | ||||
| pub unsafe extern "C" fn sp_cp437_grid_unsafe_data_ref( | ||||
|     this: *mut CCp437Grid, | ||||
| ) -> CByteSlice { | ||||
|     let data = (*this).data_ref_mut(); | ||||
|     let data = (*this).0.data_ref_mut(); | ||||
|     CByteSlice { | ||||
|         start: data.as_mut_ptr_range().start, | ||||
|         length: data.len(), | ||||
|  | @ -9,7 +9,7 @@ pub use crate::c_slice::CByteSlice; | |||
| 
 | ||||
| pub mod bit_vec; | ||||
| 
 | ||||
| pub mod byte_grid; | ||||
| pub mod brightness_grid; | ||||
| 
 | ||||
| pub mod command; | ||||
| 
 | ||||
|  | @ -19,7 +19,9 @@ pub mod packet; | |||
| 
 | ||||
| pub mod pixel_grid; | ||||
| 
 | ||||
| pub mod c_slice; | ||||
| 
 | ||||
| pub mod cp437_grid; | ||||
| 
 | ||||
| /// The minimum time needed for the display to refresh the screen in ms.
 | ||||
| pub const FRAME_PACING_MS: u32 = servicepoint::FRAME_PACING.as_millis() as u32; | ||||
| 
 | ||||
| pub mod c_slice; | ||||
|  |  | |||
|  | @ -61,45 +61,85 @@ namespace ServicePoint.BindGen | |||
|         [DllImport(__DllName, EntryPoint = "sp_bit_vec_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern CByteSlice sp_bit_vec_unsafe_data_ref(CBitVec* @this); | ||||
| 
 | ||||
|         /// <summary>Creates a new `ByteGrid` with the specified dimensions.  returns: `ByteGrid` initialized to 0.  # 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_byte_grid_dealloc`.</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_byte_grid_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern PrimitiveGrid* sp_byte_grid_new(nuint width, nuint height); | ||||
|         /// <summary>Creates a new `BrightnessGrid` with the specified dimensions.  returns: `BrightnessGrid` initialized to 0.  # 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_brightness_grid_dealloc`.</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_brightness_grid_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern CBrightnessGrid* sp_brightness_grid_new(nuint width, nuint height); | ||||
| 
 | ||||
|         /// <summary>Loads a `ByteGrid` with the specified dimensions from the provided data.  # Panics  When the provided `data_length` is not sufficient for the `height` and `width`  # Safety  The caller has to make sure that:  - `data` points to a valid memory location of at least `data_length` bytes in size. - the returned instance is freed in some way, either by using a consuming function or by explicitly calling `sp_byte_grid_dealloc`.</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_byte_grid_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern PrimitiveGrid* sp_byte_grid_load(nuint width, nuint height, byte* data, nuint data_length); | ||||
|         /// <summary>Loads a `BrightnessGrid` with the specified dimensions from the provided data.  # Panics  When the provided `data_length` is not sufficient for the `height` and `width`  # Safety  The caller has to make sure that:  - `data` points to a valid memory location of at least `data_length` bytes in size. - the returned instance is freed in some way, either by using a consuming function or by explicitly calling `sp_brightness_grid_dealloc`.</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_brightness_grid_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern CBrightnessGrid* sp_brightness_grid_load(nuint width, nuint height, byte* data, nuint data_length); | ||||
| 
 | ||||
|         /// <summary>Clones a `ByteGrid`.  # Safety  The caller has to make sure that:  - `this` points to a valid `ByteGrid` - `this` is not written to concurrently - the returned instance is freed in some way, either by using a consuming function or by explicitly calling `sp_byte_grid_dealloc`.</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_byte_grid_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern PrimitiveGrid* sp_byte_grid_clone(PrimitiveGrid* @this); | ||||
|         /// <summary>Clones a `BrightnessGrid`.  # Safety  The caller has to make sure that:  - `this` points to a valid `BrightnessGrid` - `this` is not written to concurrently - the returned instance is freed in some way, either by using a consuming function or by explicitly calling `sp_brightness_grid_dealloc`.</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_brightness_grid_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern CBrightnessGrid* sp_brightness_grid_clone(CBrightnessGrid* @this); | ||||
| 
 | ||||
|         /// <summary>Deallocates a `ByteGrid`.  # Safety  The caller has to make sure that:  - `this` points to a valid `ByteGrid` - `this` is not used concurrently or after this call - `this` was not passed to another consuming function, e.g. to create a `Command`</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_byte_grid_dealloc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern void sp_byte_grid_dealloc(PrimitiveGrid* @this); | ||||
|         /// <summary>Deallocates a `BrightnessGrid`.  # Safety  The caller has to make sure that:  - `this` points to a valid `BrightnessGrid` - `this` is not used concurrently or after this call - `this` was not passed to another consuming function, e.g. to create a `Command`</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_brightness_grid_dealloc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern void sp_brightness_grid_dealloc(CBrightnessGrid* @this); | ||||
| 
 | ||||
|         /// <summary>Gets the current value at the specified position.  # Arguments  * `this`: instance to read from * `x` and `y`: position of the cell to read  # Panics  When accessing `x` or `y` out of bounds.  # Safety  The caller has to make sure that:  - `this` points to a valid `ByteGrid` - `this` is not written to concurrently</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_byte_grid_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern byte sp_byte_grid_get(PrimitiveGrid* @this, nuint x, nuint y); | ||||
|         /// <summary>Gets the current value at the specified position.  # Arguments  * `this`: instance to read from * `x` and `y`: position of the cell to read  # Panics  When accessing `x` or `y` out of bounds.  # Safety  The caller has to make sure that:  - `this` points to a valid `BrightnessGrid` - `this` is not written to concurrently</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_brightness_grid_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern byte sp_brightness_grid_get(CBrightnessGrid* @this, nuint x, nuint y); | ||||
| 
 | ||||
|         /// <summary>Sets the value of the specified position in the `ByteGrid`.  # Arguments  * `this`: instance to write to * `x` and `y`: position of the cell * `value`: the value to write to the cell  returns: old value of the cell  # Panics  When accessing `x` or `y` out of bounds.  # Safety  The caller has to make sure that:  - `this` points to a valid `BitVec` - `this` is not written to or read from concurrently</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_byte_grid_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern void sp_byte_grid_set(PrimitiveGrid* @this, nuint x, nuint y, byte value); | ||||
|         /// <summary>Sets the value of the specified position in the `BrightnessGrid`.  # Arguments  * `this`: instance to write to * `x` and `y`: position of the cell * `value`: the value to write to the cell  returns: old value of the cell  # Panics  When accessing `x` or `y` out of bounds.  # Safety  The caller has to make sure that:  - `this` points to a valid `BitVec` - `this` is not written to or read from concurrently</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_brightness_grid_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern void sp_brightness_grid_set(CBrightnessGrid* @this, nuint x, nuint y, byte value); | ||||
| 
 | ||||
|         /// <summary>Sets the value of all cells in the `ByteGrid`.  # Arguments  * `this`: instance to write to * `value`: the value to set all cells to  # Safety  The caller has to make sure that:  - `this` points to a valid `ByteGrid` - `this` is not written to or read from concurrently</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_byte_grid_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern void sp_byte_grid_fill(PrimitiveGrid* @this, byte value); | ||||
|         /// <summary>Sets the value of all cells in the `BrightnessGrid`.  # Arguments  * `this`: instance to write to * `value`: the value to set all cells to  # Safety  The caller has to make sure that:  - `this` points to a valid `BrightnessGrid` - `this` is not written to or read from concurrently</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_brightness_grid_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern void sp_brightness_grid_fill(CBrightnessGrid* @this, byte value); | ||||
| 
 | ||||
|         /// <summary>Gets the width of the `ByteGrid` instance.  # Arguments  * `this`: instance to read from  # Safety  The caller has to make sure that:  - `this` points to a valid `ByteGrid`</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_byte_grid_width", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern nuint sp_byte_grid_width(PrimitiveGrid* @this); | ||||
|         /// <summary>Gets the width of the `BrightnessGrid` instance.  # Arguments  * `this`: instance to read from  # Safety  The caller has to make sure that:  - `this` points to a valid `BrightnessGrid`</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_brightness_grid_width", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern nuint sp_brightness_grid_width(CBrightnessGrid* @this); | ||||
| 
 | ||||
|         /// <summary>Gets the height of the `ByteGrid` instance.  # Arguments  * `this`: instance to read from  # Safety  The caller has to make sure that:  - `this` points to a valid `ByteGrid`</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_byte_grid_height", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern nuint sp_byte_grid_height(PrimitiveGrid* @this); | ||||
|         /// <summary>Gets the height of the `BrightnessGrid` instance.  # Arguments  * `this`: instance to read from  # Safety  The caller has to make sure that:  - `this` points to a valid `BrightnessGrid`</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_brightness_grid_height", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern nuint sp_brightness_grid_height(CBrightnessGrid* @this); | ||||
| 
 | ||||
|         /// <summary>Gets an unsafe reference to the data of the `ByteGrid` instance.  ## Safety  The caller has to make sure that:  - `this` points to a valid `ByteGrid` - the returned memory range is never accessed after the passed `ByteGrid` has been freed - the returned memory range is never accessed concurrently, either via the `ByteGrid` or directly</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_byte_grid_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern CByteSlice sp_byte_grid_unsafe_data_ref(PrimitiveGrid* @this); | ||||
|         /// <summary>Gets an unsafe reference to the data of the `BrightnessGrid` instance.  ## Safety  The caller has to make sure that:  - `this` points to a valid `BrightnessGrid` - the returned memory range is never accessed after the passed `BrightnessGrid` has been freed - the returned memory range is never accessed concurrently, either via the `BrightnessGrid` or directly</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_brightness_grid_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern CByteSlice sp_brightness_grid_unsafe_data_ref(CBrightnessGrid* @this); | ||||
| 
 | ||||
|         /// <summary>Creates a new `Cp437Grid` with the specified dimensions.  returns: `Cp437Grid` initialized to 0.  # 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_cp437_grid_dealloc`.</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_cp437_grid_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern CCp437Grid* sp_cp437_grid_new(nuint width, nuint height); | ||||
| 
 | ||||
|         /// <summary>Loads a `Cp437Grid` with the specified dimensions from the provided data.  # Panics  When the provided `data_length` is not sufficient for the `height` and `width`  # Safety  The caller has to make sure that:  - `data` points to a valid memory location of at least `data_length` bytes in size. - the returned instance is freed in some way, either by using a consuming function or by explicitly calling `sp_cp437_grid_dealloc`.</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_cp437_grid_load", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern CCp437Grid* sp_cp437_grid_load(nuint width, nuint height, byte* data, nuint data_length); | ||||
| 
 | ||||
|         /// <summary>Clones a `Cp437Grid`.  # Safety  The caller has to make sure that:  - `this` points to a valid `Cp437Grid` - `this` is not written to concurrently - the returned instance is freed in some way, either by using a consuming function or by explicitly calling `sp_cp437_grid_dealloc`.</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_cp437_grid_clone", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern CCp437Grid* sp_cp437_grid_clone(CCp437Grid* @this); | ||||
| 
 | ||||
|         /// <summary>Deallocates a `Cp437Grid`.  # Safety  The caller has to make sure that:  - `this` points to a valid `Cp437Grid` - `this` is not used concurrently or after this call - `this` was not passed to another consuming function, e.g. to create a `Command`</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_cp437_grid_dealloc", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern void sp_cp437_grid_dealloc(CCp437Grid* @this); | ||||
| 
 | ||||
|         /// <summary>Gets the current value at the specified position.  # Arguments  * `this`: instance to read from * `x` and `y`: position of the cell to read  # Panics  When accessing `x` or `y` out of bounds.  # Safety  The caller has to make sure that:  - `this` points to a valid `Cp437Grid` - `this` is not written to concurrently</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_cp437_grid_get", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern byte sp_cp437_grid_get(CCp437Grid* @this, nuint x, nuint y); | ||||
| 
 | ||||
|         /// <summary>Sets the value of the specified position in the `Cp437Grid`.  # Arguments  * `this`: instance to write to * `x` and `y`: position of the cell * `value`: the value to write to the cell  returns: old value of the cell  # Panics  When accessing `x` or `y` out of bounds.  # Safety  The caller has to make sure that:  - `this` points to a valid `BitVec` - `this` is not written to or read from concurrently</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_cp437_grid_set", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern void sp_cp437_grid_set(CCp437Grid* @this, nuint x, nuint y, byte value); | ||||
| 
 | ||||
|         /// <summary>Sets the value of all cells in the `Cp437Grid`.  # Arguments  * `this`: instance to write to * `value`: the value to set all cells to  # Safety  The caller has to make sure that:  - `this` points to a valid `Cp437Grid` - `this` is not written to or read from concurrently</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_cp437_grid_fill", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern void sp_cp437_grid_fill(CCp437Grid* @this, byte value); | ||||
| 
 | ||||
|         /// <summary>Gets the width of the `Cp437Grid` instance.  # Arguments  * `this`: instance to read from  # Safety  The caller has to make sure that:  - `this` points to a valid `Cp437Grid`</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_cp437_grid_width", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern nuint sp_cp437_grid_width(CCp437Grid* @this); | ||||
| 
 | ||||
|         /// <summary>Gets the height of the `Cp437Grid` instance.  # Arguments  * `this`: instance to read from  # Safety  The caller has to make sure that:  - `this` points to a valid `Cp437Grid`</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_cp437_grid_height", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern nuint sp_cp437_grid_height(CCp437Grid* @this); | ||||
| 
 | ||||
|         /// <summary>Gets an unsafe reference to the data of the `Cp437Grid` instance.  ## Safety  The caller has to make sure that:  - `this` points to a valid `Cp437Grid` - the returned memory range is never accessed after the passed `Cp437Grid` has been freed - the returned memory range is never accessed concurrently, either via the `Cp437Grid` or directly</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_cp437_grid_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|         public static extern CByteSlice sp_cp437_grid_unsafe_data_ref(CCp437Grid* @this); | ||||
| 
 | ||||
|         /// <summary>Tries to turn a `Packet` into a `Command`. The packet is deallocated in the process.  Returns: pointer to new `Command` instance or NULL  # Safety  The caller has to make sure that:  - `packet` points to a valid instance of `Packet` - `packet` is not used concurrently or after this call - the result is checked for NULL - the returned `Command` instance is freed in some way, either by using a consuming function or by explicitly calling `sp_command_dealloc`.</summary> | ||||
|         [DllImport(__DllName, EntryPoint = "sp_command_try_from_packet", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] | ||||
|  | @ -231,6 +271,16 @@ namespace ServicePoint.BindGen | |||
|     { | ||||
|     } | ||||
| 
 | ||||
|     [StructLayout(LayoutKind.Sequential)] | ||||
|     public unsafe partial struct CBrightnessGrid | ||||
|     { | ||||
|     } | ||||
| 
 | ||||
|     [StructLayout(LayoutKind.Sequential)] | ||||
|     public unsafe partial struct CCp437Grid | ||||
|     { | ||||
|     } | ||||
| 
 | ||||
|     [StructLayout(LayoutKind.Sequential)] | ||||
|     public unsafe partial struct CByteSlice | ||||
|     { | ||||
|  |  | |||
|  | @ -5,7 +5,8 @@ fn main() { | |||
|     println!("cargo::rerun-if-changed=build.rs"); | ||||
|     csbindgen::Builder::default() | ||||
|         .input_extern_file("../servicepoint_binding_c/src/bit_vec.rs") | ||||
|         .input_extern_file("../servicepoint_binding_c/src/byte_grid.rs") | ||||
|         .input_extern_file("../servicepoint_binding_c/src/brightness_grid.rs") | ||||
|         .input_extern_file("../servicepoint_binding_c/src/cp437_grid.rs") | ||||
|         .input_extern_file("../servicepoint_binding_c/src/command.rs") | ||||
|         .input_extern_file("../servicepoint_binding_c/src/connection.rs") | ||||
|         .input_extern_file("../servicepoint_binding_c/src/pixel_grid.rs") | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vinzenz Schroeter
						Vinzenz Schroeter