MME2 changes - Propped commits from openmme/paging branch. Added scripts
for code gen

Change-Id: Ie55032217232214ac8544ca76ea34335205329e4
diff --git a/scripts/GtpV2StackCodeGen/tts/ietemplate.cpp.tt b/scripts/GtpV2StackCodeGen/tts/ietemplate.cpp.tt
new file mode 100644
index 0000000..2e1a131
--- /dev/null
+++ b/scripts/GtpV2StackCodeGen/tts/ietemplate.cpp.tt
@@ -0,0 +1,445 @@
+/*
+ * Copyright 2019-present Infosys Limited  
+ *   
+ * SPDX-License-Identifier: Apache-2.0    
+ */
+/******************************************************************************
+ *
+ * This is an auto generated file.
+ * Please do not edit this file.
+ * All edits to be made through template source file
+ * <TOP-DIR/scripts/GtpV2StackCodeGen/tts/ietemplate.cpp.tt>
+ ******************************************************************************/
+
+#include "[% tempdata.fileName %].h"
+#include "dataTypeCodecUtils.h"
+
+[% tempdata.className %]::[% tempdata.className %]() 
+{
+    ieType = [% tempdata.ieTypeVal %];
+    // TODO
+
+}
+
+[% tempdata.className %]::~[% tempdata.className %]() {
+    // TODO Auto-generated destructor stub
+}
+
+bool [% tempdata.className %]::encode[% tempdata.className %](MsgBuffer &buffer, [% tempdata.className %]Data const &data)
+{
+[% IF validationPresent == "y" -%]
+    if (!([% validationRule %]))
+    {
+        errorStream.add((char *)"Data validation failure at IE : [% tempdata.className %]\n");
+        return false; 
+    }[% END -%]
+[% FOREACH Item IN tempdata.sequence -%]
+[% IF Item -%]
+[% IF Item.skipType == "y" -%]
+    buffer.skip[% Item.bitByte %]([% Item.skipValue %]);
+
+[% ELSE -%]
+[% IF Item.presence == "optional" -%]
+    if (data.[% Item.fieldName %]Present)
+    {
+[% IF Item.encodeConditional == "y" -%]
+        if ([% Item.encodeCondition %])
+        {
+[% IF Item.leafType == "y" -%]
+[% IF Item.validationPresent == "y" -%]
+            if (!([% Item.validationRule %]))
+            {
+                errorStream.add((char *)"Data validation failure: [% Item.fieldName %]\n");
+                return false; 
+            }
+[% END -%]
+[% IF Item.bitField == "y" -%]
+            if(!(buffer.writeBits(data.[% Item.fieldName %], [% Item.fieldSize %])))
+            {
+                errorStream.add((char *)"Encoding of [% Item.fieldName %] failed\n");
+                return false;
+            }
+[% ELSE -%]
+            if (!(buffer.write[% Item.fieldType %](data.[% Item.fieldName %])))
+            {
+                errorStream.add((char *)"Encoding of [% Item.fieldName %] failed\n");
+                return false;
+            }
+[% END -%]
+[% ELSE -%]
+[% IF Item.validationPresent == "y" -%]
+            if (!([% Item.validationRule %]))
+            {
+                errorStream.add((char *)"Data validation failure: [% Item.fieldName %]\n");
+                return false; 
+            }
+[% END -%]
+            if (!(DataTypeCodecUtils::encode[% Item.fieldType %](buffer, data.[% Item.fieldName %])))
+            {
+                errorStream.add((char *)"Encoding of [% Item.fieldName %] failed\n");
+                return false;
+            }
+[% END -%]
+        }
+    }
+[% ELSE -%]
+[% IF Item.leafType == "y" -%]
+[% IF Item.validationPresent == "y" -%]
+        if (!([% Item.validationRule %]))
+        {
+            errorStream.add((char *)"Data validation failure: [% Item.fieldName %]\n");
+            return false; 
+        }
+[% END -%]
+[% IF Item.bitField == "y" -%]
+        if(!(buffer.writeBits(data.[% Item.fieldName %], [% Item.fieldSize %])))
+        {
+            errorStream.add((char *)"Encoding of [% Item.fieldName %] failed\n");
+            return false;
+        }
+[% ELSE -%]
+        if (!(buffer.write[% Item.fieldType %](data.[% Item.fieldName %])))
+        {
+            errorStream.add((char *)"Encoding of [% Item.fieldName %] failed\n");
+            return false;
+        }
+[% END -%]
+[% ELSE -%]
+[% IF Item.validationPresent == "y" -%]
+        if (!([% Item.validationRule %]))
+        {
+            errorStream.add((char *)"Data validation failure: [% Item.fieldName %]\n");
+            return false; 
+        }
+[% END -%]
+        if (!(DataTypeCodecUtils::encode[% Item.fieldType %](buffer, data.[% Item.fieldName %])))
+        {
+            errorStream.add((char *)"Encoding of [% Item.fieldName %] failed\n");
+            return false;
+        }
+[% END -%]
+    }
+[% END -%]
+[% ELSE -%]
+[% IF Item.encodeConditional == "y" -%]
+    if ([% Item.encodeCondition %])
+    {
+[% IF Item.leafType == "y" -%]
+[% IF Item.validationPresent == "y" -%]
+        if (!([% Item.validationRule %]))
+        {
+            errorStream.add((char *)"Data validation failure: [% Item.fieldName %]\n");
+            return false; 
+        }
+[% END -%]
+[% IF Item.bitField == "y" -%]
+        if(!(buffer.writeBits(data.[% Item.fieldName %], [% Item.fieldSize %])))
+        {
+            errorStream.add((char *)"Encoding of [% Item.fieldName %] failed\n");
+            return false;
+        }
+[% ELSE -%]
+        if (!(buffer.write[% Item.fieldType %](data.[% Item.fieldName %])))
+        {
+    errorStream.add((char *)"Encoding of [% Item.fieldName %] failed\n");
+    return false;
+        }
+[% END -%]
+[% ELSE -%]
+[% IF Item.validationPresent == "y" -%]
+        if (!([% Item.validationRule %]))
+        {
+            errorStream.add((char *)"Data validation failure: [% Item.fieldName %]\n");
+            return false; 
+        }
+[% END -%]
+        if (!(DataTypeCodecUtils::encode[% Item.fieldType %](buffer, data.[% Item.fieldName %])))
+        {
+            errorStream.add((char *)"Encoding of [% Item.fieldName %] failed\n");
+            return false;
+        }
+[% END -%]
+    }
+[% ELSE -%]
+[% IF Item.leafType == "y" -%]
+[% IF Item.validationPresent == "y" -%]
+    if (!([% Item.validationRule %]))
+    {
+        errorStream.add((char *)"Data validation failure: [% Item.fieldName %]\n");
+        return false; 
+    }
+[% END -%]
+[% IF Item.bitField == "y" -%]
+    if(!(buffer.writeBits(data.[% Item.fieldName %], [% Item.fieldSize %])))
+    {
+        errorStream.add((char *)"Encoding of [% Item.fieldName %] failed\n");
+        return false;
+    }
+[% ELSE -%]
+    if (!(buffer.write[% Item.fieldType %](data.[% Item.fieldName %])))
+    {
+        errorStream.add((char *)"Encoding of [% Item.fieldName %] failed\n");
+        return false;
+    }
+[% END -%]
+[% ELSE -%]
+[% IF Item.validationPresent == "y" -%]
+    if (!([% Item.validationRule %]))
+    {
+        errorStream.add((char *)"Data validation failure: [% Item.fieldName %]\n");
+        return false; 
+    }
+[% END -%]
+    if (!(DataTypeCodecUtils::encode[% Item.fieldType %](buffer, data.[% Item.fieldName %])))
+    {
+    errorStream.add((char *)"Encoding of [% Item.fieldName %] failed\n");
+    return false;
+    }
+[% END -%]
+[% END -%]
+[% END -%]
+[% END -%]
+[% END -%]
+[% END %]
+    return true;
+}
+
+bool [% tempdata.className %]::decode[% tempdata.className %](MsgBuffer &buffer, [% tempdata.className %]Data &data, Uint16 length)
+{ 
+[%- flag = 0 -%]
+    
+    // TODO optimize the length checks
+    
+    Uint16 ieBoundary = buffer.getCurrentIndex() + length;
+[% FOREACH Item IN tempdata.sequence -%]
+[% IF Item.length == "lengthLeft" -%][%- IF flag == 0 %]
+    Uint16 lengthLeft = length;
+    [%- flag = 1 %]
+[% END -%][% END -%]
+[% IF Item.skipType == "y" -%]
+    buffer.skip[% Item.bitByte %]([% Item.skipValue %]);
+    if (buffer.getCurrentIndex() > ieBoundary)
+    {
+        errorStream.add((char *)"Attempt to read beyond IE boundary: [% Item.fieldName %]\n");
+        return false;
+    }
+
+[% ELSE -%]
+[% IF Item.decodeConditional == "y" %]
+    if ([% Item.decodeCondition %])
+    {
+[% IF Item.leafType == "y" -%]
+[% IF Item.bitField == "y" -%]
+        data.[% Item.fieldName %] = buffer.readBits([% Item.fieldSize %]);
+        // confirm that we are not reading beyond the IE boundary
+        if (buffer.getCurrentIndex() > ieBoundary)
+        {
+            errorStream.add((char *)"Attempt to read beyond IE boundary: [% Item.fieldName %]\n");
+            return false;
+        }
+[% ELSE %]
+        buffer.read[% Item.fieldType %](data.[% Item.fieldName %]);
+        if (buffer.getCurrentIndex() > ieBoundary)
+        {
+            errorStream.add((char *)"Attempt to read beyond IE boundary: [% Item.fieldName %]\n");
+            return false;
+        }
+[% END -%]
+[% IF Item.validationPresent == "y" -%]
+        if (!([% Item.validationRule %]))
+        {
+            errorStream.add((char *)"Data validation failure : [% Item.fieldName %]\n");
+            return false; //TODO need to add validations
+        }
+[% END -%]
+[% ELSE -%]
+[% IF Item.length == "lengthLeft" -%]
+        lengthLeft = ieBoundary - buffer.getCurrentIndex();
+[% END -%]
+[% IF Item.arrayType == "y" -%]
+        if (!(DataTypeCodecUtils::decode[% Item.fieldType %](buffer, data.[% Item.fieldName %], [% Item.length %], [% Item.count %])))
+[% ELSE -%]
+        if (!(DataTypeCodecUtils::decode[% Item.fieldType %](buffer, data.[% Item.fieldName %], [% Item.length %])))
+[% END -%]
+        {
+            errorStream.add((char *)"Failed to decode: [% Item.fieldName %]\n");
+            return false;
+        }
+[% IF Item.validationPresent == "y" -%]
+        if (!([% Item.validationRule %]))
+        {
+            errorStream.add((char *)"Data validation failure : [% Item.fieldName %]\n");
+            return false; //TODO need to add validations
+        }
+[% END -%]
+[% END -%]
+[% IF Item.presence == "optional" -%]
+        data.[% Item.fieldName %]Present = true;
+[% END -%]
+    }
+[% ELSE -%]
+[% IF Item.leafType == "y" -%]
+[% IF Item.bitField == "y" -%]
+    data.[% Item.fieldName %] = buffer.readBits([% Item.fieldSize %]);
+    // confirm that we are not reading beyond the IE boundary
+    if (buffer.getCurrentIndex() > ieBoundary)
+    {
+        errorStream.add((char *)"Attempt to read beyond IE boundary: [% Item.fieldName %]\n");
+        return false;
+    }
+[% ELSE %]
+    buffer.read[% Item.fieldType %](data.[% Item.fieldName %]);
+    if (buffer.getCurrentIndex() > ieBoundary)
+    {
+        errorStream.add((char *)"Attempt to read beyond IE boundary: [% Item.fieldName %]\n");
+        return false;
+    }
+[% END -%]
+[% IF Item.validationPresent == "y" -%]
+    if (!([% Item.validationRule %]))
+    {
+        errorStream.add((char *)"Data validation failure : [% Item.fieldName %]\n");
+        return false; //TODO need to add validations
+    }
+[% END -%]
+[% ELSE -%]
+[% IF Item.length == "lengthLeft" -%]
+    lengthLeft = ieBoundary - buffer.getCurrentIndex();
+[% END -%]
+[% IF Item.arrayType == "y" -%]
+    if (!(DataTypeCodecUtils::decode[% Item.fieldType %](buffer, data.[% Item.fieldName %], [% Item.length %], [% Item.count %])))
+[% ELSE -%]
+    if (!(DataTypeCodecUtils::decode[% Item.fieldType %](buffer, data.[% Item.fieldName %], [% Item.length %])))
+[% END -%]
+    {
+        errorStream.add((char *)"Failed to decode: [% Item.fieldName %]\n");
+        return false;
+    }
+[% IF Item.validationPresent == "y" -%]
+    if (!([% Item.validationRule %]))
+    {
+        errorStream.add((char *)"Data validation failure : [% Item.fieldName %]\n");
+        return false; //TODO need to add validations
+    }
+[% END -%]
+[% END -%]
+[% IF Item.presence == "optional" -%]
+    data.[% Item.fieldName %]Present = true;
+[% END -%]
+[% END -%]
+[% END -%]
+[% END -%]
+[% IF validationPresent == "y" -%]
+    if (!([% validationRule %]))
+    {
+        errorStream.add((char *)"Data validation failure at IE: [% tempdata.className %]\n");
+        return false;
+    }
+[% END -%]
+
+    // The IE is decoded now. The buffer index should be pointing to the 
+    // IE Boundary. If not, we have some more data left for the IE which we don't know
+    // how to decode
+    if (ieBoundary == buffer.getCurrentIndex())
+    {
+        return true;
+    }
+    else
+    {
+        errorStream.add((char *)"Unable to decode IE [% tempdata.className %]\n");
+        return false;
+    }
+}
+void [% tempdata.className %]::display[% tempdata.className %]_v([% tempdata.className %]Data const &data, Debug &stream)
+{
+    stream.incrIndent();
+    stream.add((char *)"[% tempdata.className %]Data:");
+    stream.incrIndent();
+    stream.endOfLine();
+[% FOREACH Item IN tempdata.sequence -%]
+[% IF Item.skipType != "y" -%]
+  
+[% IF Item.presence == "optional" -%]  
+    if (data.[% Item.fieldName %]Present)
+    {
+[% IF Item.encodeConditional == "y" -%]
+        if ([% Item.encodeCondition %])
+        {
+[% IF Item.leafType == "y" -%]
+[% IF Item.bitField == "y" -%]
+            stream.add((char *) "[% Item.fieldName %]: "); 
+            stream.add((Uint8)data.[% Item.fieldName %]);
+            stream.endOfLine();
+[% ELSE -%]
+            stream.add((char *)"[% Item.fieldName %]: ");
+            stream.add(data.[% Item.fieldName %]);
+            stream.endOfLine();
+[% END -%]
+[% ELSE -%]
+            stream.add((char *)"[% Item.fieldName %]:");
+            stream.endOfLine();
+            DataTypeCodecUtils::display[% Item.fieldType %]_v(data.[% Item.fieldName %], stream);
+[% END -%]
+        }
+    }
+[% ELSE -%] 
+[% IF Item.leafType == "y" -%]
+[% IF Item.bitField == "y" -%]
+        stream.add((char *) "[% Item.fieldName %]: "); 
+        stream.add((Uint8)data.[% Item.fieldName %]);
+        stream.endOfLine();
+[% ELSE -%]
+        stream.add((char *)"[% Item.fieldName %]: ");
+        stream.add(data.[% Item.fieldName %]);
+        stream.endOfLine();
+[% END -%]
+[% ELSE -%]
+        stream.add((char *)"[% Item.fieldName %]:");
+        stream.endOfLine();
+        DataTypeCodecUtils::display[% Item.fieldType %]_v(data.[% Item.fieldName %], stream);
+[% END -%]
+    }   
+[% END -%]
+[% ELSE -%]
+[% IF Item.encodeConditional == "y" -%]
+    if ([% Item.encodeCondition %])
+    {
+[% IF Item.leafType == "y" -%]
+[% IF Item.bitField == "y" -%]
+        stream.add( (char *)"[% Item.fieldName %]: "); 
+        stream.add((Uint8)data.[% Item.fieldName %]);
+        stream.endOfLine();
+[% ELSE -%]
+        stream.add((char *)"[% Item.fieldName %]: ");
+        stream.add(data.[% Item.fieldName %]);
+        stream.endOfLine();
+[% END -%]
+[% ELSE -%]
+        stream.add((char *)"[% Item.fieldName %]:");
+        stream.endOfLine();
+        DataTypeCodecUtils::display[% Item.fieldType %]_v(data.[% Item.fieldName %], stream);
+[% END -%]
+    }
+[% ELSE -%] 
+[% IF Item.leafType == "y" -%]
+[% IF Item.bitField == "y" -%]
+    stream.add( (char *)"[% Item.fieldName %]: "); 
+    stream.add((Uint8)data.[% Item.fieldName %]);
+    stream.endOfLine();
+[% ELSE -%]
+    stream.add((char *)"[% Item.fieldName %]: ");
+    stream.add(data.[% Item.fieldName %]);
+    stream.endOfLine();
+[% END -%]
+[% ELSE -%]
+    stream.add((char *)"[% Item.fieldName %]:");
+    stream.endOfLine();
+    DataTypeCodecUtils::display[% Item.fieldType %]_v(data.[% Item.fieldName %], stream);
+[% END -%]
+[% END -%]
+[% END -%]
+[% END -%]
+[% END -%]
+    stream.decrIndent();
+    stream.decrIndent();
+}