add functions to convert containers directly into packet

This commit is contained in:
Vinzenz Schroeter 2025-04-12 22:13:29 +02:00
parent 1e442012be
commit baa450b2f7
10 changed files with 178 additions and 20 deletions

View file

@ -455,6 +455,18 @@ size_t sp_bitmap_height(Bitmap */*notnull*/ bitmap);
*/
SPBitVec */*notnull*/ sp_bitmap_into_bitvec(Bitmap */*notnull*/ bitmap);
/**
* Creates a [BitmapCommand] and immediately turns that into a [Packet].
*
* The provided [Bitmap] gets consumed.
*
* Returns NULL in case of an error.
*/
Packet *sp_bitmap_into_packet(Bitmap */*notnull*/ bitmap,
size_t x,
size_t y,
CompressionCode compression);
/**
* Loads a [Bitmap] with the specified dimensions from the provided data.
*
@ -580,6 +592,18 @@ void sp_bitvec_free(SPBitVec */*notnull*/ bit_vec);
*/
bool sp_bitvec_get(SPBitVec */*notnull*/ bit_vec, size_t index);
/**
* Creates a [BitVecCommand] and immediately turns that into a [Packet].
*
* The provided [SPBitVec] gets consumed.
*
* Returns NULL in case of an error.
*/
Packet *sp_bitvec_into_packet(SPBitVec */*notnull*/ bitvec,
size_t offset,
BinaryOperation operation,
CompressionCode compression);
/**
* Returns true if length is 0.
*
@ -695,6 +719,13 @@ Brightness sp_brightness_grid_get(BrightnessGrid */*notnull*/ brightness_grid,
*/
size_t sp_brightness_grid_height(BrightnessGrid */*notnull*/ brightness_grid);
/**
* Creates a [BrightnessGridCommand] and immediately turns that into a [Packet].
*
* The provided [BrightnessGrid] gets consumed.
*
* Returns NULL in case of an error.
*/
Packet *sp_brightness_grid_into_packet(BrightnessGrid */*notnull*/ grid,
size_t x,
size_t y);
@ -818,6 +849,17 @@ uint32_t sp_char_grid_get(CharGrid */*notnull*/ char_grid, size_t x, size_t y);
*/
size_t sp_char_grid_height(CharGrid */*notnull*/ char_grid);
/**
* Creates a [CharGridCommand] and immediately turns that into a [Packet].
*
* The provided [CharGrid] gets consumed.
*
* Returns NULL in case of an error.
*/
Packet *sp_char_grid_into_packet(CharGrid */*notnull*/ grid,
size_t x,
size_t y);
/**
* Loads a [CharGrid] with the specified dimensions from the provided data.
*
@ -1045,6 +1087,17 @@ uint8_t sp_cp437_grid_get(Cp437Grid */*notnull*/ cp437_grid,
*/
size_t sp_cp437_grid_height(Cp437Grid */*notnull*/ cp437_grid);
/**
* Creates a [Cp437GridCommand] and immediately turns that into a [Packet].
*
* The provided [Cp437Grid] gets consumed.
*
* Returns NULL in case of an error.
*/
Packet *sp_cp437_grid_into_packet(Cp437Grid */*notnull*/ grid,
size_t x,
size_t y);
/**
* Loads a [Cp437Grid] with the specified dimensions from the provided data.
*/
@ -1156,7 +1209,13 @@ void sp_packet_set_payload(Packet */*notnull*/ packet, ByteSlice data);
*/
Packet *sp_packet_try_load(ByteSlice data);
bool sp_u16_to_command_code(uint16_t code, CommandCode *result);
/**
* Converts u16 into [CommandCode].
*
* If the provided value is not valid, false is returned and result is not changed.
*/
bool sp_u16_to_command_code(uint16_t code,
CommandCode *result);
/**
* Closes and deallocates a [UdpConnection].