diff --git a/MAC/GCF/TM/autogen/protocol.tpl b/MAC/GCF/TM/autogen/protocol.tpl index e364fc13457510eab237b8ad89f6596c203eae0a..7303339c6d6ac41427e16dd96d895f32596baa70 100644 --- a/MAC/GCF/TM/autogen/protocol.tpl +++ b/MAC/GCF/TM/autogen/protocol.tpl @@ -119,12 +119,12 @@ extern const char* [+ protocol_name +]_signalnames[]; void* [+ event_class_name +]::pack(uint32& __packsize) { - [+ FOR param "" +][+ IF (or (*== (get "type") "[]") (*== (get "type") "*")) +]assert([+ (get "name") +]);[+ ENDIF +] + [+ FOR param "" +][+ IF (or (*== (get "type") "[]") (*== (get "type") "*")) +][+ IF (*== (get "type") "[]") +]if ([+ (get "name") +]NOE > 0) [+ ENDIF +]assert([+ (get "name") +]);[+ ENDIF +] [+ ENDFOR +] uint32 __requiredSize = [+ IF (not (exist? "noheader")) +]sizeof(signal) + sizeof(length)[+ ELSE +]0[+ ENDIF +][+ FOR param "" +] [+ IF (exist? "userdefined") +]+ [+ (get "name") +][+ IF (*== (get "type") "*") +]->[+ ELSE +].[+ ENDIF +]getSize() [+ ELIF (not (*== (get "type") "]")) +]+ [+ IF (== (get "type") "string") +][+ (get "name") +].length() + sizeof(uint16)[+ ELSE +]sizeof([+ (get "name") +])[+ ENDIF+] - [+ ELIF (*== (get "type") "[]") +]+ sizeof([+ (get "name") +]NOE) + ([+ (get "name") +]NOE * sizeof([+ (get "name") +][0])) + [+ ELIF (*== (get "type") "[]") +]+ sizeof([+ (get "name") +]NOE) + ([+ (get "name") +]NOE * sizeof([+ event_class_member_type +])) [+ ELSE +]+ sizeof([+ (get "name") +])[+ ENDIF +][+ ENDFOR +]; resizeBuf(__requiredSize); @@ -142,7 +142,7 @@ void* [+ event_class_name +]::pack(uint32& __packsize) __offset += sizeof([+ (get "type") +]); [+ ENDIF +] [+ ELIF (*== (get "type") "[]") +] - __offset += packMember(__offset, [+ (get "name") +], [+ (get "name") +]NOE, sizeof([+ (get "name") +][0])); + __offset += packMember(__offset, [+ (get "name") +], [+ (get "name") +]NOE, sizeof([+ event_class_member_type +])); [+ ELSE +] memcpy(_buffer + __offset, [+ (get "name") +], sizeof([+ (get "name") +])); __offset += sizeof([+ (get "name") +]); @@ -179,7 +179,7 @@ void [+ event_class_name +]::unpack() __offset += sizeof([+ (get "type") +]); [+ ENDIF +] [+ ELIF (*== (get "type") "[]") +] - [+ (get "name") +] = ([+ event_class_member_type +]*) unpackMember(__data, __offset, [+ (get "name") +]NOE, sizeof([+ (get "name") +][0])); + [+ (get "name") +] = ([+ event_class_member_type +]*) unpackMember(__data, __offset, [+ (get "name") +]NOE, sizeof([+ event_class_member_type +])); [+ ELSE +] memcpy([+ (get "name") +], (__data + __offset), sizeof([+ (get "name") +])); __offset += sizeof([+ (get "name") +]); diff --git a/MAC/GCF/TM/src/GCF_Event.cc b/MAC/GCF/TM/src/GCF_Event.cc index 3833b359428a1e32e5e95a5d2e047acf05f48f7c..2e92ad85a5522134fd6a324e55ccc4b2e3691178 100644 --- a/MAC/GCF/TM/src/GCF_Event.cc +++ b/MAC/GCF/TM/src/GCF_Event.cc @@ -68,7 +68,7 @@ void* GCFEvent::unpackMember(char* data, uint32& offset, uint32& memberNOE, uint void* seqPtr(0); memcpy(&memberNOE, data + offset, sizeof(memberNOE)); seqPtr = data + offset + sizeof(memberNOE); - offset += sizeof(memberNOE) + memberNOE * sizeofMemberType; + offset += sizeof(memberNOE) + (memberNOE * sizeofMemberType); return seqPtr; } @@ -77,7 +77,10 @@ uint32 GCFEvent::packMember(uint32 offset, const void* member, uint32 memberNOE, assert(_buffer); memcpy(_buffer + offset, &memberNOE, sizeof(memberNOE)); offset += sizeof(memberNOE); - memcpy(_buffer + offset, member, memberNOE * sizeofMemberType); + if (memberNOE > 0) + { + memcpy(_buffer + offset, member, memberNOE * sizeofMemberType); + } return (memberNOE * sizeofMemberType) + sizeof(memberNOE); }