IVGCVSW-4072 Add stream header to Timeline Message Directory packet

 * Refactored the WriteTimelineMessageDirectoryPacket function
 * Added the stream header to the packet
 * Updated decoders/parsers
 * Updated unit tests accordingly
 * Minor refactoring

Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com>
Change-Id: I58f15fde54adc6414ca9fd5fb8d6157cad867339
diff --git a/src/profiling/ProfilingUtils.hpp b/src/profiling/ProfilingUtils.hpp
index f7b46be..4427140 100644
--- a/src/profiling/ProfilingUtils.hpp
+++ b/src/profiling/ProfilingUtils.hpp
@@ -25,13 +25,20 @@
 namespace profiling
 {
 
+struct SwTraceHeader
+{
+    uint8_t m_StreamVersion;
+    uint8_t m_PointerBytes;
+    uint8_t m_ThreadIdBytes;
+};
+
 struct SwTraceMessage
 {
-    uint32_t id;
-    std::string name;
-    std::string uiName;
-    std::vector<char> argTypes;
-    std::vector<std::string> argNames;
+    uint32_t m_Id;
+    std::string m_Name;
+    std::string m_UiName;
+    std::vector<char> m_ArgTypes;
+    std::vector<std::string> m_ArgNames;
 };
 
 struct SwTraceCharPolicy
@@ -52,6 +59,29 @@
     }
 };
 
+struct SwTraceTypeCharPolicy
+{
+    static bool IsValidChar(unsigned char c)
+    {
+        // Check that the given character is among the allowed ones
+        switch (c)
+        {
+        case '@':
+        case 't':
+        case 'i':
+        case 'I':
+        case 'l':
+        case 'L':
+        case 'F':
+        case 'p':
+        case 's':
+            return true; // Valid char
+        default:
+            return false; // Invalid char
+        }
+    }
+};
+
 template <typename SwTracePolicy>
 bool IsValidSwTraceString(const std::string& s)
 {
@@ -87,6 +117,23 @@
     return true;
 }
 
+template <typename SwTracePolicy,
+          typename SwTraceBuffer = std::vector<uint32_t>>
+bool ConvertDirectoryComponent(const std::string& directoryComponent, SwTraceBuffer& swTraceBuffer)
+{
+    // Convert the directory component using the given policy
+    SwTraceBuffer tempSwTraceBuffer;
+    bool result = StringToSwTraceString<SwTracePolicy>(directoryComponent, tempSwTraceBuffer);
+    if (!result)
+    {
+        return false;
+    }
+
+    swTraceBuffer.insert(swTraceBuffer.end(), tempSwTraceBuffer.begin(), tempSwTraceBuffer.end());
+
+    return true;
+}
+
 uint16_t GetNextUid(bool peekOnly = false);
 
 std::vector<uint16_t> GetNextCounterUids(uint16_t cores);
@@ -103,6 +150,8 @@
 
 void WriteUint16(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint16_t value);
 
+void WriteUint8(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint8_t value);
+
 void WriteBytes(unsigned char* buffer, unsigned int offset, const void* value, unsigned int valueSize);
 
 void WriteUint64(unsigned char* buffer, unsigned int offset, uint64_t value);
@@ -111,6 +160,8 @@
 
 void WriteUint16(unsigned char* buffer, unsigned int offset, uint16_t value);
 
+void WriteUint8(unsigned char* buffer, unsigned int offset, uint8_t value);
+
 void ReadBytes(const IPacketBufferPtr& packetBuffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[]);
 
 uint64_t ReadUint64(const IPacketBufferPtr& packetBuffer, unsigned int offset);