You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2020/05/12 16:58:15 UTC

[celix] 01/01: Update the wire protocol to use fixed size types instead of compiler/platform dependent ones (so uint32_t instead of unsigned int)

This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch feature/wire_protocol_with_fixed_sized_types
in repository https://gitbox.apache.org/repos/asf/celix.git

commit 3807e417db648885df38c9a96d6a2e30893e797f
Author: Pepijn Noltes <pe...@gmail.com>
AuthorDate: Tue May 12 18:57:48 2020 +0200

    Update the wire protocol to use fixed size types instead of compiler/platform dependent ones (so uint32_t instead of unsigned int)
---
 .../src/pubsub_tcp_topic_receiver.c                |  2 +-
 .../src/pubsub_wire_protocol_common.c              | 12 +++++------
 .../pubsub/pubsub_spi/include/pubsub_protocol.h    | 23 ++++++++++++----------
 3 files changed, 20 insertions(+), 17 deletions(-)

diff --git a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_topic_receiver.c b/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_topic_receiver.c
index 8cbf8fc..1a34d92 100644
--- a/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_topic_receiver.c
+++ b/bundles/pubsub/pubsub_admin_tcp/src/pubsub_tcp_topic_receiver.c
@@ -563,7 +563,7 @@ processMsgForSubscriberEntry(pubsub_tcp_topic_receiver_t *receiver, psa_tcp_subs
             }
         }
     } else {
-        L_WARN("[PSA_ZMQ_TR] Cannot find serializer for type id 0x%X", message->header.msgId);
+        L_WARN("[PSA_TCP_TR] Cannot find serializer for type id 0x%X. Received payload size is %u.", message->header.msgId, message->payload.length);
     }
 }
 
diff --git a/bundles/pubsub/pubsub_protocol_wire_v1/src/pubsub_wire_protocol_common.c b/bundles/pubsub/pubsub_protocol_wire_v1/src/pubsub_wire_protocol_common.c
index 5c83dd2..2f07375 100644
--- a/bundles/pubsub/pubsub_protocol_wire_v1/src/pubsub_wire_protocol_common.c
+++ b/bundles/pubsub/pubsub_protocol_wire_v1/src/pubsub_wire_protocol_common.c
@@ -30,13 +30,13 @@
 int readShort(const unsigned char *data, int offset, uint16_t *val) {
     memcpy(val, data + offset, sizeof(uint16_t));
     *val = ntohs(*val);
-    return offset + sizeof(uint16_t);
+    return offset + (int)sizeof(uint16_t);
 }
 
 int readInt(const unsigned char *data, int offset, uint32_t *val) {
     memcpy(val, data + offset, sizeof(uint32_t));
     *val = ntohl(*val);
-    return offset + sizeof(uint32_t);
+    return offset + (int)sizeof(uint32_t);
 }
 
 int readLong(const unsigned char *data, int offset, uint64_t *val) {
@@ -46,19 +46,19 @@ int readLong(const unsigned char *data, int offset, uint64_t *val) {
 #else
     *val = be64toh(*val);
 #endif
-    return offset + sizeof(uint64_t);
+    return offset + (int)sizeof(uint64_t);
 }
 
 int writeShort(unsigned char *data, int offset, uint16_t val) {
     uint16_t nVal = htons(val);
     memcpy(data + offset, &nVal, sizeof(uint16_t));
-    return offset + sizeof(uint16_t);
+    return offset + (int)sizeof(uint16_t);
 }
 
 int writeInt(unsigned char *data, int offset, uint32_t val) {
     uint32_t nVal = htonl(val);
     memcpy(data + offset, &nVal, sizeof(uint32_t));
-    return offset + sizeof(uint32_t);
+    return offset + (int)sizeof(uint32_t);
 }
 
 int writeLong(unsigned char *data, int offset, uint64_t val) {
@@ -68,5 +68,5 @@ int writeLong(unsigned char *data, int offset, uint64_t val) {
     uint64_t nVal = htobe64(val);
 #endif
     memcpy(data + offset, &nVal, sizeof(uint64_t));
-    return offset + sizeof(uint64_t);
+    return offset + (int)sizeof(uint64_t);
 }
diff --git a/bundles/pubsub/pubsub_spi/include/pubsub_protocol.h b/bundles/pubsub/pubsub_spi/include/pubsub_protocol.h
index 2ed8f81..ecf336f 100644
--- a/bundles/pubsub/pubsub_spi/include/pubsub_protocol.h
+++ b/bundles/pubsub/pubsub_spi/include/pubsub_protocol.h
@@ -20,6 +20,7 @@
 #ifndef PUBSUB_PROTOCOL_SERVICE_H_
 #define PUBSUB_PROTOCOL_SERVICE_H_
 
+#include <stdint.h>
 #include "celix_properties.h"
 
 #define PUBSUB_PROTOCOL_SERVICE_NAME      "pubsub_protocol"
@@ -32,27 +33,29 @@ typedef struct pubsub_protocol_header pubsub_protocol_header_t;
  * The protocol header structure, contains the information about the message payload and metadata
  */
 struct pubsub_protocol_header {
-  /** message payload identification attributes */
-    unsigned int msgId;
-    unsigned short msgMajorVersion;
-    unsigned short msgMinorVersion;
+    /** message payload identification attributes */
+    uint32_t msgId;
+    uint16_t msgMajorVersion;
+    uint16_t msgMinorVersion;
 
     /** Payload and metadata sizes attributes */
-    unsigned int payloadSize;
-    unsigned int metadataSize;
+    uint32_t payloadSize;
+    uint32_t metadataSize;
 
     /** Optional message segmentation attributes, these attributes are only used/written by the protocol admin.
      *  When message segmentation is supported by the protocol admin */
-    unsigned int seqNr;
-    unsigned int payloadPartSize;
-    unsigned int payloadOffset;
+    uint32_t seqNr;
+    uint32_t payloadPartSize;
+    uint32_t payloadOffset;
+
+    uint32_t padding; //to arrange alignment on 64 bit
 };
 
 typedef struct pubsub_protocol_payload pubsub_protocol_payload_t;
 
 struct pubsub_protocol_payload {
     void *payload;
-    size_t length;
+    uint32_t length;
 };
 
 typedef struct pubsub_protocol_metadata pubsub_protocol_metadata_t;