Exemple #1
0
        private static List<KeyValuesNode> ParseNext(ref IEnumerable<byte> data, int lvl)
        {
            List<KeyValuesNode> thisnode = new List<KeyValuesNode>();

            byte next;

            do
            {
                next = data.First<byte>();
                data = data.Skip<byte>(1);

                String name = null;
                if (next != TK_VAR_TERMINATOR)
                    name = ParseString(ref data);

                switch (next)
                {
                    case TK_VAR_SECTION:
                        KeyValuesCollection node = new KeyValuesCollection(name);
                        node.AddAll(ParseNext(ref data, lvl + 1));
                        thisnode.Add(node);
                        break;
                    case TK_VAR_STRING:
                    case TK_VAR_STRINGP:
                        thisnode.Add(new KeyValuesPair<String>(name, ParseString(ref data)));
                        break;
                    case TK_VAR_INT:
                        thisnode.Add(new KeyValuesPair<Int32>(name, ParseInt32(ref data)));
                        break;
                    case TK_VAR_UINT:
                        thisnode.Add(new KeyValuesPair<Int64>(name, ParseUInt32(ref data)));
                        break;
                    case TK_VAR_INT64:
                        thisnode.Add(new KeyValuesPair<Int64>(name, ParseInt64(ref data)));
                        break;
                    case TK_VAR_UINT64:
                        thisnode.Add(new KeyValuesPair<UInt64>(name, ParseUInt64(ref data)));
                        break;
                    case TK_VAR_TERMINATOR:
                        return thisnode;
                    default:
                        throw new FormatException("Unexpected byte.");
                }
            }
            while (next != TK_VAR_TERMINATOR || data.Count<byte>() > 1);

            return thisnode;
        }
Exemple #2
0
        private static void SaveSection(FileStream st, KeyValuesCollection cl)
        {
            st.WriteByte(TK_VAR_SECTION);

            SaveString(st, cl.Name);

            foreach (KeyValuesNode child in cl.Childs)
            {
                SaveNode(st, child);
            }

            st.WriteByte(TK_VAR_TERMINATOR);
        }