Exemplo n.º 1
0
        public void Parse(string protoAsText)
        {
            _protoAsText = protoAsText;
            int currentLevel = 0;
            var root         = new MsgMatrixElement(0, null, protoAsText);

            _matrix.Add(root);
            bool prevColon             = false;                       // to process colons in string attributes
            var  currentParentMessages = new Dictionary <int, int>(); // level: indexInMatrix

            for (int i = 0; i < _protoAsText.Length; i++)
            {
                char c = _protoAsText[i];
                int  indexInMatrix;
                switch (c)
                {
                case ':' when !prevColon:
                    _matrixAttrs.Add(new AttrMatrixElement(i, currentLevel, _protoAsText));
                    if (currentParentMessages.TryGetValue(currentLevel, out indexInMatrix))
                    {
                        _matrix[indexInMatrix].AttributeIndexes.Add(_matrixAttrs.Count - 1);
                    }
                    else
                    {
                        root.AttributeIndexes.Add(_matrixAttrs.Count - 1);
                    }

                    prevColon = true;
                    break;

                case '{' when !prevColon:
                    currentLevel++;
                    _matrix.Add(new MsgMatrixElement(i, currentLevel, _protoAsText));
                    if (currentParentMessages.TryGetValue(currentLevel - 1, out indexInMatrix))
                    {
                        _matrix[indexInMatrix].ChildIndexes.Add(_matrix.Count - 1);
                    }
                    else
                    {
                        root.ChildIndexes.Add(_matrix.Count - 1);
                    }

                    currentParentMessages[currentLevel] = _matrix.Count - 1;
                    break;

                case '}' when !prevColon:
                    currentLevel--;
                    break;

                case '\n':
                    prevColon = false;
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public List <string> GetKeys() // TODO: check usage. I doubt it really should return a LIST of ALL sub messages
        {
            var res = new List <string>();

            for (int i = 0; i < _matrix.Count; i++)
            {
                MsgMatrixElement el = _matrix[i];
                if (el.Level >= _level)
                {
                    res.Add(el.Name);
                }
            }

            return(res);
        }
Exemplo n.º 3
0
        public ProtoMessage2 GetElement(string name)
        {
            for (int i = 0; i < _matrix.Count; i++)
            {
                MsgMatrixElement el = _matrix[i];
                if (el.Level != _level || el.Name != name)
                {
                    continue;
                }

                return(new ProtoMessage2(_matrix, _matrixAttrs, _level + 1, _protoAsText, i));
            }

            return(null);
        }