Example #1
0
        private TLVList Decode(TLV Parent, byte[] binaryStructureFile, SymbolTable DocFile)
        {
            var newTlvList = new TLVList();
            int i          = 0;

            while (i < binaryStructureFile.Length - 1)
            {
                byte getItentification = binaryStructureFile[i++];
                int  sizeOfElement     = 0;
                if (getItentification == 64)
                {
                    sizeOfElement = (binaryStructureFile[i++] << 8) | binaryStructureFile[i++];
                }
                else
                {
                    sizeOfElement = binaryStructureFile[i++];
                }
                Param findParamElement   = getTLVCode(DocFile, getItentification);
                var   getContextToDecode = new byte[sizeOfElement];

                Array.Copy(binaryStructureFile, i, getContextToDecode, 0, sizeOfElement);
                i += sizeOfElement;
                if (findParamElement != null)
                {
                    bool itsGroup = findParamElement.Group != null ? true : false;
                    if (itsGroup)
                    {
                        //Get some solution for format activating difrent type of class
                        TLV newTlvElement = TLV.Create(findParamElement, getContextToDecode);
                        newTlvElement.setParent(Parent);
                        newTlvElement.children = Decode(newTlvElement, getContextToDecode, findParamElement.Group);
                        DebugEvent(ref newTlvElement);
                        newTlvList.Add(newTlvElement);
                    }
                    else
                    {
                        TLV newTlvElement = TLV.Create(findParamElement, getContextToDecode);
                        newTlvElement.setParent(Parent);
                        DebugEvent(ref newTlvElement);
                        newTlvList.Add(newTlvElement);
                    }
                }
                if (findParamElement == null)
                {
                    TLV newTlvElement = new TLVGeneric("GenericTLV", getItentification, getContextToDecode);
                    newTlvElement.setParent(Parent);
                    DebugEvent(ref newTlvElement);
                    newTlvList.Add(newTlvElement);
                }
            }
            return(newTlvList);
        }
Example #2
0
        private TLVList Encode(TLV Parent, string FileToParse, SymbolTable DocFile)
        {
            var NewTlvList = new TLVList();

            while (true)
            {
                int PosLine  = FileToParse.IndexOf(';');
                int PosGroup = FileToParse.IndexOf('{');
                if (PosLine < 0 && PosGroup < 0)
                {
                    break;
                }
                if (PosLine > PosGroup && PosGroup > -1)
                {
                    // Exclude Comment Before Began // # /* */
                    //We Find Post Group Recursive Call
                    string Name =
                        FileToParse.Substring(0, PosGroup).Replace('\n', ' ').Replace('\r', ' ').Replace('\t', ' ').Trim
                            ();
                    if (Name.StartsWith("/*"))
                    {
                        Name = Name.Substring(Name.IndexOf("*/") + 2).Trim();
                    }
                    LastCommand = Name;
                    if (Name != "Main")
                    {
                        Param  FindElem      = DocFile[Name];
                        string FileToParse2  = Split(FileToParse.Substring(PosGroup));
                        string Manage        = FileToParse2.Substring(1, FileToParse2.Length - 2);
                        TLV    newTlvElement = TLV.Create(FindElem, "");
                        newTlvElement.setParent(Parent);
                        newTlvElement.children = Encode(newTlvElement, Manage, FindElem.Group);
                        FileToParse            = FileToParse.Substring(PosGroup + FileToParse2.Length);
                        NewTlvList.Add(newTlvElement);
                        DebugEvent(ref newTlvElement);
                    }
                    else
                    {
                        string FileToParse2 = Split(FileToParse.Substring(PosGroup));
                        string Manage       = FileToParse2.Substring(1, FileToParse2.Length - 2);
                        NewTlvList  = Encode(null, Manage, DocFile);
                        FileToParse = FileToParse.Substring(PosGroup + FileToParse2.Length);
                    }
                }
                else
                {
                    var    getRegEx = new Regex(@"\b.*?;");
                    string NewValue = getRegEx.Match(FileToParse).ToString().Replace('\t', ' ').Replace('\n', ' ');
                    // string NewVal = FileToParse.Substring(0, PosLine ).Trim();
                    string SymbolName = NewValue.Split(' ')[0];
                    LastCommand = SymbolName;
                    NewValue    = NewValue.Substring(SymbolName.Length + 1, NewValue.IndexOf(';') - SymbolName.Length - 1);
                    FileToParse = FileToParse.Substring(PosLine + 1);
                    if (SymbolName != "GenericTLV")
                    {
                        TLV NewTlvElement = TLV.Create(DocFile[SymbolName], NewValue);

                        NewTlvElement.setParent(Parent);
                        DebugEvent(ref NewTlvElement);
                        NewTlvList.Add(NewTlvElement);
                    }
                    else
                    {
                        TLV NewTlvElement = new TLVGeneric(SymbolName, NewValue);
                        NewTlvElement.setParent(Parent);
                        DebugEvent(ref NewTlvElement);
                        NewTlvList.Add(NewTlvElement);
                    }
                }
            }
            return(NewTlvList);
        }