namespace Giants.BinTools
{
using System.IO;
using System.Text;
public static class Extensions
{
///
/// Reads a null-terminated C-string from the binary reader.
///
public static string ReadCString(this BinaryReader reader)
{
var stringBuilder = new StringBuilder();
while (true)
{
char c = reader.ReadChar();
if (c == '\0')
{
break;
}
stringBuilder.Append(c);
}
return stringBuilder.ToString();
}
///
/// Writes a null-terminated C-string to the binary writer.
///
public static void WriteCString(this BinaryWriter writer, string value)
{
writer.Write(Encoding.UTF8.GetBytes(value));
writer.Write('\0');
}
}
}