using System;
using System.Runtime.InteropServices;
using System.IO;
// ReSharper disable once CheckNamespace
namespace NAudio.Wave
{
///
/// This class used for marshalling from unmanaged code
///
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 2)]
public class WaveFormatExtraData : WaveFormat
{
// try with 100 bytes for now, increase if necessary
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 100)]
private byte[] extraData = new byte[100];
///
/// Allows the extra data to be read
///
public byte[] ExtraData => extraData;
///
/// parameterless constructor for marshalling
///
internal WaveFormatExtraData()
{
}
///
/// Reads this structure from a BinaryReader
///
public WaveFormatExtraData(BinaryReader reader)
: base(reader)
{
ReadExtraData(reader);
}
internal void ReadExtraData(BinaryReader reader)
{
if (this.extraSize > 0)
{
reader.Read(extraData, 0, extraSize);
}
}
///
/// Writes this structure to a BinaryWriter
///
public override void Serialize(BinaryWriter writer)
{
base.Serialize(writer);
if (extraSize > 0)
{
writer.Write(extraData, 0, extraSize);
}
}
}
}