internal static BcfNode ReadNode(BcfNode node, FileStream stream) { BinaryReader br = new BinaryReader(stream); int count = br.ReadInt32(); string name = br.ReadString(); for (int i = 0; i < count; i++) { EnumBcfTag tag = (EnumBcfTag)br.ReadByte(); string tag_name = br.ReadString(); switch (tag) { case EnumBcfTag.STRING: node.Set(tag_name, br.ReadString()); break; case EnumBcfTag.INTEGER: node.Set(tag_name, br.ReadInt32()); break; case EnumBcfTag.BOOLEAN: node.Set(tag_name, br.ReadBoolean()); break; case EnumBcfTag.SUBNODE: BcfNode subnode = node.CreateSubnode(tag_name); BcfNode.ReadNode(subnode, stream); break; } } return node; }
internal static void SaveNode(BcfNode node, FileStream stream) { BinaryWriter bw = new BinaryWriter(stream); bw.Write((int)node.Items.Count); bw.Write(node.Name); string[] names = node.Items.Keys.ToArray(); for (int i = 0; i < node.Items.Count; i++) { string name = names[i]; object value = node.Items[name]; EnumBcfTag tag = GetTag(value); bw.Write((byte)tag); bw.Write(name); switch (tag) { case EnumBcfTag.INTEGER: bw.Write((int)value); break; case EnumBcfTag.STRING: bw.Write((string)value); break; case EnumBcfTag.BOOLEAN: bw.Write((bool)value); break; case EnumBcfTag.SUBNODE: BcfNode subnode = (BcfNode)value; SaveNode(subnode, stream); break; } } }
internal BcfFile(FileStream stream) { this.Root = new BcfNode(""); this.BaseStream = stream; }