public void Write(BinaryWriter writer, IEnumerable<string> materials)
        {
            writer.Write(materials.Count());

            foreach (string material in materials)
            {
                writer.WriteLpString(material);
            }
        }
        public void Write(BinaryWriter writer)
        {
            writer.WriteBooleanAsInt32(IsPartOfALayer);
            if (IsPartOfALayer)
            {
                writer.Write(LayerDeclaration);
                writer.Write(LayerMasks.Count());
                foreach (uint mask in LayerMasks)
                {
                    writer.Write(mask);
                }
            }

            writer.Write(GroupId);

            writer.WriteLpString(EntityName);
            foreach (var pair in Fields)
            {
                writer.Write(NewAttributeDeclaration);
                TypeSerializer.Write(writer, pair.Key, pair.Value);
            }
        }
        public void Write(BinaryWriter writer, string name, IType type)
        {
            long sizePosition = writer.BaseStream.Position;
            writer.Seek(4, SeekOrigin.Current);
            long startPos = writer.BaseStream.Position;
            writer.WriteLpString(name);
            writer.Write(type.TypeId);
            writer.Write(type.NumFields);
            writer.Write(0);
            type.Write(writer);
            long endPos = writer.BaseStream.Position;

            int length = (int)(endPos - startPos);
            writer.Seek((int)sizePosition, SeekOrigin.Begin);
            writer.Write(length);
            writer.Seek((int)endPos, SeekOrigin.Begin);
        }
        public void BinaryWriter_WriteLpString()
        {
            byte[] writtenData;
            using (var stream = new MemoryStream())
            {
                using (var writer = new BinaryWriter(stream))
                {
                    writer.WriteLpString("hello world");
                }
                writtenData = stream.ToArray();
            }

            byte[] expected = { 0x0B, 0x00, 0x00, 0x00, 0x68, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x77, 0x6F, 0x72, 0x6C, 0x64 };

            Assert.AreEqual(BitConverter.ToString(expected), BitConverter.ToString(writtenData));
            Assert.AreEqual(expected.Length, writtenData.Length);
        }