Skip to content

Commit

Permalink
feat(pubsub): Support fields with arraydimensions for the raw encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
jpfr committed Oct 20, 2024
1 parent 8a27295 commit 7ab2096
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
18 changes: 12 additions & 6 deletions src/pubsub/ua_pubsub_networkmessage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1461,12 +1461,18 @@ UA_DataSetMessage_decodeBinary(const UA_ByteString *src, size_t *offset, UA_Data
/* TODO The datatype reference should be part of the internal
* pubsub configuration to avoid the time-expensive lookup */
const UA_DataType *type =
UA_findDataTypeWithCustom(&dsm->fields[i].dataType,
customTypes);
dst->data.keyFrameData.rawFields.length += type->memSize;
UA_STACKARRAY(UA_Byte, value, type->memSize);
rv = UA_decodeBinaryInternal(&dst->data.keyFrameData.rawFields,
&tmpOffset, value, type, NULL);
UA_findDataTypeWithCustom(&dsm->fields[i].dataType, customTypes);
size_t arraySize = 1;
for(size_t j = 0; j < dsm->fields[i].arrayDimensionsSize; j++)
arraySize *= dsm->fields[i].arrayDimensions[j];
dst->data.keyFrameData.rawFields.length += arraySize * type->memSize;
UA_STACKARRAY(UA_Byte, value, arraySize * type->memSize);
UA_Byte *valpos = value;
for(size_t j = 0; j < arraySize; j++) {
rv |= UA_decodeBinaryInternal(&dst->data.keyFrameData.rawFields,
&tmpOffset, valpos, type, NULL);
valpos += type->memSize;
}
UA_CHECK_STATUS(rv, return rv);
if(dsm->fields[i].maxStringLength != 0) {
if(type->typeKind == UA_DATATYPEKIND_STRING ||
Expand Down
25 changes: 17 additions & 8 deletions src/pubsub/ua_pubsub_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -779,16 +779,25 @@ DataSetReader_processRaw(UA_Server *server, UA_ReaderGroup *rg,
size_t offset = 0;
msg->data.keyFrameData.rawFields.length = 0;
for(size_t i = 0; i < dsr->config.dataSetMetaData.fieldsSize; i++) {
UA_FieldMetaData *fmd = &dsr->config.dataSetMetaData.fields[i];
/* TODO The datatype reference should be part of the internal
* pubsub configuration to avoid the time-expensive lookup */
const UA_DataType *type =
UA_findDataTypeWithCustom(&dsr->config.dataSetMetaData.fields[i].dataType,
server->config.customDataTypes);
msg->data.keyFrameData.rawFields.length += type->memSize;
UA_STACKARRAY(UA_Byte, value, type->memSize);
UA_StatusCode res =
UA_decodeBinaryInternal(&msg->data.keyFrameData.rawFields,
&offset, value, type, NULL);
UA_findDataTypeWithCustom(&fmd->dataType, server->config.customDataTypes);
size_t arraySize = 1;
for(size_t j = 0; j < fmd->arrayDimensionsSize; j++)
arraySize *= fmd->arrayDimensions[j];
msg->data.keyFrameData.rawFields.length += arraySize * type->memSize;
UA_STACKARRAY(UA_Byte, value, arraySize * type->memSize);

UA_StatusCode res = UA_STATUSCODE_GOOD;
UA_Byte *valpos = value;
for(size_t j = 0; j < arraySize; j++) {
res |= UA_decodeBinaryInternal(&msg->data.keyFrameData.rawFields,
&offset, valpos, type, NULL);
valpos += type->memSize;
}

if(dsr->config.dataSetMetaData.fields[i].maxStringLength != 0) {
if(type->typeKind == UA_DATATYPEKIND_STRING ||
type->typeKind == UA_DATATYPEKIND_BYTESTRING) {
Expand All @@ -815,7 +824,7 @@ DataSetReader_processRaw(UA_Server *server, UA_ReaderGroup *rg,
tv->beforeWrite(server, &dsr->identifier, &dsr->linkedReaderGroup,
&tv->targetVariable.targetNodeId,
tv->targetVariableContext, tv->externalDataValue);
memcpy((*tv->externalDataValue)->value.data, value, type->memSize);
memcpy((*tv->externalDataValue)->value.data, value, arraySize * type->memSize);
if(tv->afterWrite)
tv->afterWrite(server, &dsr->identifier, &dsr->linkedReaderGroup,
&tv->targetVariable.targetNodeId,
Expand Down

0 comments on commit 7ab2096

Please sign in to comment.