diff options
Diffstat (limited to 'lib/pbdrv/pb-msg.c')
-rw-r--r-- | lib/pbdrv/pb-msg.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/pbdrv/pb-msg.c b/lib/pbdrv/pb-msg.c index ead9f09..8ffd7cc 100644 --- a/lib/pbdrv/pb-msg.c +++ b/lib/pbdrv/pb-msg.c @@ -3,30 +3,35 @@ #include "pb-msg.h" #include "pb-serial.h" -pbdrv_buf_t pbdrv_msg_write(const pb_msg_t * msg) { - pbdrv_buf_t buf = { 0 }; +pb_buf_t pb_msg_write(const pb_msg_t * msg) { + pb_buf_t buf = { 0 }; mpack_writer_t writer; mpack_writer_init_growable(&writer, &buf.data, &buf.size); - pbdrv_serialize(&writer, msg); + pb_ser_w(&writer, msg); mpack_writer_destroy(&writer); return buf; } -pb_msg_t * pbdrv_msg_read(const pbdrv_buf_t * buf) { +pb_msg_t * pb_msg_read(const pb_buf_t * buf) { mpack_reader_t reader; mpack_reader_init_data(&reader, buf->data, buf->size); pb_msg_t * msg = malloc(sizeof(pb_msg_t)); - pbdrv_deserialize(&reader, msg); + pb_ser_r(&reader, msg); + mpack_reader_destroy(&reader); return msg; } -void pbdrv_msg_free(pb_msg_t * msg) { - pbdrv_free(msg); +void pb_msg_free(pb_msg_t * msg) { + // free message fields recursively + pb_ser_free(msg); + + // free message container that was created in \p pb_msg_read + free(msg); } |