private bool WriteProperty(BinaryWriter stream, ref KeyValuePair pair)
        {
            WriteString(stream, pair.Name);

            if (pair.Name == "None")
            {
                return(true);
            }

            MemoryStream chunk       = new MemoryStream();
            BinaryWriter chunkStream = new BinaryWriter(chunk);

            if (pair.GetPairType() == KeyValuePairType.String)
            {
                KeyValuePairString str = (KeyValuePairString)pair;
                WriteString(stream, new StringField("StrProperty"));

                WriteString(chunkStream, str.Value);
            }
            else if (pair.GetPairType() == KeyValuePairType.Array)
            {
                KeyValuePairArray arr = (KeyValuePairArray)pair;
                WriteString(stream, new StringField("ArrayProperty"));

                UInt32 numElements = (UInt32)arr.Values.Count;
                chunkStream.Write(numElements);

                foreach (var elem in arr.Values)
                {
                    WriteString(chunkStream, elem);
                }
            }

            UInt64 totalLength = (UInt64)chunk.Length;

            stream.Write(totalLength);
            stream.Write(chunk.GetBuffer(), 0, (int)chunk.Length);

            return(true);
        }
        private bool ReadProperty(BinaryReader stream)
        {
            StringField pairName = new StringField("None");

            if (!ReadString(stream, ref pairName))
            {
                return(false);
            }

            if (pairName != "None")
            {
                StringField propertyType = new StringField("");
                if (!ReadString(stream, ref propertyType))
                {
                    return(false);
                }

                // Unused for now.
                UInt64 propertyLength = stream.ReadUInt64();

                if (propertyType == "StrProperty")
                {
                    KeyValuePairString pair = new KeyValuePairString();
                    pair.Name = pairName;

                    if (!ReadString(stream, ref pair.Value))
                    {
                        return(false);
                    }

                    _properties.Add(pair);
                }
                else if (propertyType == "ArrayProperty")
                {
                    KeyValuePairArray pair = new KeyValuePairArray();
                    pair.Name = pairName;

                    UInt32 numElements = stream.ReadUInt32();
                    for (UInt32 n = 0; n < numElements; n++)
                    {
                        StringField elem = new StringField("");
                        if (!ReadString(stream, ref elem))
                        {
                            return(false);
                        }
                        pair.Values.Add(elem);
                    }

                    _properties.Add(pair);
                }
            }
            else
            {
                KeyValuePair pair = new KeyValuePair();
                pair.Name = pairName;

                _properties.Add(pair);
            }

            return(true);
        }