From a4b56107aacd9acdc99b9d751f4d4f5499b43dfe Mon Sep 17 00:00:00 2001 From: Robby Zambito Date: Sun, 3 Mar 2024 15:46:18 -0500 Subject: [PATCH] Add deserialize function --- libguestfs-inspect.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libguestfs-inspect.h b/libguestfs-inspect.h index 7f8c02a..e156b18 100644 --- a/libguestfs-inspect.h +++ b/libguestfs-inspect.h @@ -49,3 +49,26 @@ static zmsg_t *command_to_zmsg(struct guestfs_inpsect_command *command) { return res; } +static struct guestfs_inpsect_command *zmsg_to_command(zmsg_t *msg) { + struct guestfs_inpsect_command *res = malloc(sizeof(struct guestfs_inpsect_command)); + + res->name = zmsg_popstr(msg); + zframe_t *next = zmsg_pop(msg); + res->command = *(zframe_data(next)); + free(next); + + switch (res->command) { + case GUESTFS_COMMAND_LS: + next = zmsg_pop(msg); + res->args.ls.paths_length = *(zframe_data(next)); + free(next); + + res->args.ls.paths = calloc(res->args.ls.paths_length, sizeof(char *)); + + for (size_t i = 0; i < res->args.ls.paths_length; i++) { + res->args.ls.paths[i] = zmsg_popstr(msg); + } + break; + } + return res; +}