diff --git a/servicepoint2-binding-c/servicepoint2.h b/servicepoint2-binding-c/servicepoint2.h index 07ca43e..b8b0681 100644 --- a/servicepoint2-binding-c/servicepoint2.h +++ b/servicepoint2-binding-c/servicepoint2.h @@ -93,7 +93,7 @@ typedef struct sp2_Packet sp2_Packet; typedef struct sp2_PixelGrid sp2_PixelGrid; /** - * Represents a `&mut [u8]` as a struct usable by C code. + * Represents a span of memory (`&mut [u8]` ) as a struct usable by C code. * * Usage of this type is inherently unsafe. */ @@ -145,6 +145,11 @@ void sp2_bit_vec_fill(struct sp2_BitVec *this_, bool value); */ bool sp2_bit_vec_get(const struct sp2_BitVec *this_, size_t index); +/** + * Returns true if length is 0. + */ +bool sp2_bit_vec_is_empty(const struct sp2_BitVec *this_); + /** * Gets the length of the `BitVec` in bits. */ @@ -343,13 +348,6 @@ struct sp2_Command *sp2_command_hard_reset(void); */ struct sp2_Command *sp2_command_try_from_packet(struct sp2_Packet *packet); -/** - * Tries to load a `Command` from the passed array with the specified length. - * - * returns: NULL in case of an error, pointer to the allocated command otherwise - */ -struct sp2_Command *sp2_command_try_load(const uint8_t *data, size_t length); - /** * Closes and deallocates a connection instance */ @@ -371,11 +369,25 @@ struct sp2_Connection *sp2_connection_open(const char *host); bool sp2_connection_send(const struct sp2_Connection *connection, struct sp2_Packet *command_ptr); +/** + * Deallocates a `Packet`. + * + * Note: do not call this if the instance has been consumed in another way, e.g. by sending it. + */ +void sp2_packet_dealloc(struct sp2_Packet *this_); + /** * Turns a `Command` into a `Packet`. The command gets deallocated in the process. */ struct sp2_Packet *sp2_packet_from_command(struct sp2_Command *command); +/** + * Tries to load a `Packet` from the passed array with the specified length. + * + * returns: NULL in case of an error, pointer to the allocated packet otherwise + */ +struct sp2_Packet *sp2_packet_try_load(const uint8_t *data, size_t length); + /** * Clones a `PixelGrid`. * The returned instance has to be freed with `pixel_grid_dealloc`. diff --git a/servicepoint2-binding-cs/src/BindGen/ServicePoint2.g.cs b/servicepoint2-binding-cs/src/BindGen/ServicePoint2.g.cs index f960506..c94c6c0 100644 --- a/servicepoint2-binding-cs/src/BindGen/ServicePoint2.g.cs +++ b/servicepoint2-binding-cs/src/BindGen/ServicePoint2.g.cs @@ -50,6 +50,11 @@ namespace ServicePoint2.BindGen [DllImport(__DllName, EntryPoint = "sp2_bit_vec_len", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] public static extern nuint sp2_bit_vec_len(BitVec* @this); + /// Returns true if length is 0. + [DllImport(__DllName, EntryPoint = "sp2_bit_vec_is_empty", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + [return: MarshalAs(UnmanagedType.U1)] + public static extern bool sp2_bit_vec_is_empty(BitVec* @this); + /// Gets an unsafe reference to the data of the `BitVec` instance. ## Safety The caller has to make sure to never access the returned memory after the `BitVec` instance has been consumed or manually deallocated. Reading and writing concurrently to either the original instance or the returned data will result in undefined behavior. [DllImport(__DllName, EntryPoint = "sp2_bit_vec_unsafe_data_ref", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] public static extern CByteSlice sp2_bit_vec_unsafe_data_ref(BitVec* @this);