diff --git a/examples/posix/testing_nanopb.c b/examples/posix/testing_nanopb.c index 79021558..4d70b61f 100644 --- a/examples/posix/testing_nanopb.c +++ b/examples/posix/testing_nanopb.c @@ -9,31 +9,37 @@ int main() { - TaggedMessage original_message; - TaggedMessage deserialized_message; + FederateMessage msg; + FederateMessage deserialized; + + msg.type = MessageType_TAGGED_MESSAGE; + msg.which_message = FederateMessage_tagged_message_tag; + + TaggedMessage *original_message = &msg.message.tagged_message; unsigned char buffer[BUFFER_SIZE]; unsigned char *message = NULL; int message_size = 0; - original_message.conn_id = MSG_ID; + original_message->conn_id = MSG_ID; const char *text = "Hello World1234"; - memcpy(original_message.payload.bytes, text, sizeof("Hello World1234")); // NOLINT - original_message.payload.size = sizeof("Hello World1234"); + memcpy(original_message->payload.bytes, text, sizeof("Hello World1234")); // NOLINT + original_message->payload.size = sizeof("Hello World1234"); message = buffer; - message_size = encode_protobuf(&original_message, buffer, BUFFER_SIZE); + message_size = encode_protobuf(&msg, buffer, BUFFER_SIZE); if (message_size < 0) { printf("encoding failed!\n"); exit(1); } - int remaining_bytes = decode_protobuf(&deserialized_message, message, message_size); + int remaining_bytes = decode_protobuf(&deserialized, message, message_size); if (remaining_bytes < 0) { printf("decoding failed!\n"); exit(1); } - printf("o: %i d: %i\n", original_message.conn_id, deserialized_message.conn_id); - printf("o: %s d: %s\n", (char *)original_message.payload.bytes, (char *)deserialized_message.payload.bytes); + printf("o: %i d: %i\n", original_message->conn_id, deserialized.message.tagged_message.conn_id); + printf("o: %s d: %s\n", (char *)original_message->payload.bytes, + (char *)deserialized.message.tagged_message.payload.bytes); } \ No newline at end of file diff --git a/examples/posix/testing_posix_tcp_ip_channel_client.c b/examples/posix/testing_posix_tcp_ip_channel_client.c index b795ffc2..38a3ce18 100644 --- a/examples/posix/testing_posix_tcp_ip_channel_client.c +++ b/examples/posix/testing_posix_tcp_ip_channel_client.c @@ -14,11 +14,15 @@ int main() { unsigned short port = 8902; // NOLINT // message for server - TaggedMessage port_message; - port_message.conn_id = 42; // NOLINT + FederateMessage msg; + msg.type = MessageType_TAGGED_MESSAGE; + msg.which_message = FederateMessage_tagged_message_tag; + + TaggedMessage *port_message = &msg.message.tagged_message; + port_message->conn_id = 42; // NOLINT const char *message = "Hello World1234"; - memcpy(port_message.payload.bytes, message, sizeof("Hello World1234")); // NOLINT - port_message.payload.size = sizeof("Hello World1234"); + memcpy(port_message->payload.bytes, message, sizeof("Hello World1234")); // NOLINT + port_message->payload.size = sizeof("Hello World1234"); // creating a server that listens on loopback device on port 8900 TcpIpChannel_ctor(&channel, host, port, AF_INET); @@ -28,13 +32,13 @@ int main() { for (int i = 0; i < NUM_ITER; i++) { // sending message - channel.super.send(&channel.super, &port_message); - + channel.super.send(&channel.super, &msg); // waiting for reply - TaggedMessage *received_message = channel.super.receive(&channel.super); + const FederateMessage *received_message = channel.super.receive(&channel.super); + const TaggedMessage *received_tagged_message = &received_message->message.tagged_message; - printf("Received message with connection number %i and content %s\n", received_message->conn_id, - (char *)received_message->payload.bytes); + printf("Received message with connection number %i and content %s\n", received_tagged_message->conn_id, + (char *)received_tagged_message->payload.bytes); } channel.super.close(&channel.super); diff --git a/examples/posix/testing_posix_tcp_ip_channel_server.c b/examples/posix/testing_posix_tcp_ip_channel_server.c index 68bee971..5d5cbcf7 100644 --- a/examples/posix/testing_posix_tcp_ip_channel_server.c +++ b/examples/posix/testing_posix_tcp_ip_channel_server.c @@ -25,9 +25,10 @@ int main() { for (int i = 0; i < NUM_ITER; i++) { // waiting for messages from client - TaggedMessage *message = channel.super.receive(&channel.super); - printf("Received message with connection number %i and content %s\n", message->conn_id, - (char *)message->payload.bytes); + const FederateMessage *message = channel.super.receive(&channel.super); + const TaggedMessage *tagged_message = &message->message.tagged_message; + printf("Received message with connection number %i and content %s\n", tagged_message->conn_id, + (char *)tagged_message->payload.bytes); channel.super.send(&channel.super, message); } diff --git a/examples/posix/testing_tcp_ip_channel_server_callback.c b/examples/posix/testing_tcp_ip_channel_server_callback.c index c6a4e50c..b5651f85 100644 --- a/examples/posix/testing_tcp_ip_channel_server_callback.c +++ b/examples/posix/testing_tcp_ip_channel_server_callback.c @@ -5,9 +5,10 @@ #include TcpIpChannel channel; -void callback_handler(FederatedConnectionBundle *self, TaggedMessage *msg) { +void callback_handler(FederatedConnectionBundle *self, const FederateMessage *_msg) { + const TaggedMessage *msg = &_msg->message.tagged_message; printf("Received message with connection number %i and content %s\n", msg->conn_id, (char *)msg->payload.bytes); - channel.super.send(&channel.super, msg); + channel.super.send(&channel.super, _msg); } int main() {