| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #include "nodeinstance/create/v1/creation.pb.h" |
| 4 | #include "node_creation.h" |
| 5 | |
| 6 | #include "schema_wrapper_utils.h" |
| 7 | |
| 8 | #include <stdlib.h> |
| 9 | |
| 10 | char *generate_node_instance_creation(size_t *len, const node_instance_creation_t *data) |
| 11 | { |
| 12 | nodeinstance::create::v1::CreateNodeInstance msg; |
| 13 | |
| 14 | if (data->claim_id) |
| 15 | msg.set_claim_id(data->claim_id); |
| 16 | msg.set_machine_guid(data->machine_guid); |
| 17 | msg.set_hostname(data->hostname); |
| 18 | msg.set_hops(data->hops); |
| 19 | |
| 20 | *len = PROTO_COMPAT_MSG_SIZE(msg); |
| 21 | char *bin = (char*)mallocz(*len); |
| 22 | if (bin) |
| 23 | msg.SerializeToArray(bin, *len); |
| 24 | |
| 25 | return bin; |
| 26 | } |
| 27 | |
| 28 | node_instance_creation_result_t parse_create_node_instance_result(const char *data, size_t len) |
| 29 | { |
| 30 | nodeinstance::create::v1::CreateNodeInstanceResult msg; |
| 31 | node_instance_creation_result_t res = { .node_id = NULL, .machine_guid = NULL }; |
| 32 | |
| 33 | if (!msg.ParseFromArray(data, len)) |
| 34 | return res; |
| 35 | |
| 36 | res.node_id = strdupz(msg.node_id().c_str()); |
| 37 | res.machine_guid = strdupz(msg.machine_guid().c_str()); |
| 38 | return res; |
| 39 | } |