Просмотр исходного кода

PubSub: Don't "invent" unique MessageIds in the encoding layer

Julius Pfrommer лет назад: 5
Родитель
Сommit
62f727d2b3

+ 3 - 9
src/pubsub/ua_pubsub_networkmessage_json.c

@@ -133,16 +133,10 @@ UA_NetworkMessage_encodeJson_internal(const UA_NetworkMessage* src, CtxJson *ctx
 
         /* Table 91 – JSON NetworkMessage Definition
          * MessageId | String | A globally unique identifier for the message.
-         * This value is mandatory. */
+         * This value is mandatory. But we don't check uniqueness in the
+         * encoding layer. */
         rv |= writeJsonKey(ctx, UA_DECODEKEY_MESSAGEID);
-        /* If a messageId is given use it, otherwise generate a GUID(-string).
-         * MessageId is always decoded as a string. */
-        if(src->messageIdEnabled){
-            rv |= encodeJsonInternal(&src->messageId, &UA_TYPES[UA_TYPES_STRING], ctx);
-        } else {
-            UA_Guid guid = UA_Guid_random();
-            rv |= encodeJsonInternal(&guid, &UA_TYPES[UA_TYPES_GUID], ctx);
-        }
+        rv |= encodeJsonInternal(&src->messageId, &UA_TYPES[UA_TYPES_STRING], ctx);
 
         /* MessageType */
         rv |= writeJsonKey(ctx, UA_DECODEKEY_MESSAGETYPE);

+ 1 - 5
tests/pubsub/check_pubsub_encoding_json.c

@@ -162,20 +162,16 @@ START_TEST(UA_PubSub_EnDecode) {
     UA_Variant_setScalarCopy(&m.payload.dataSetPayload.dataSetMessages[1].data.keyFrameData.dataSetFields[1].value, &iv64, &UA_TYPES[UA_TYPES_INT64]);
     m.payload.dataSetPayload.dataSetMessages[1].data.keyFrameData.dataSetFields[1].hasValue = true;
 
-    UA_StatusCode rv = UA_STATUSCODE_UNCERTAININITIALVALUE;
-
     size_t size = UA_NetworkMessage_calcSizeJson(&m, NULL, 0, NULL, 0, true);
-    ck_assert(size == 318);
 
     UA_ByteString buffer;
-    rv = UA_ByteString_allocBuffer(&buffer, size);
+    UA_StatusCode rv = UA_ByteString_allocBuffer(&buffer, size);
     ck_assert_int_eq(rv, UA_STATUSCODE_GOOD);
 
     UA_Byte *bufPos = buffer.data;
     memset(bufPos, 0, size);
     const UA_Byte *bufEnd = &(buffer.data[buffer.length]);
 
-
     rv = UA_NetworkMessage_encodeJson(&m, &bufPos, &bufEnd, NULL, 0, NULL, 0, true);
     //*bufPos = 0;
     // then