/// <summary> /// Adds support for parsing the SizeT type /// </summary> /// <param name="size">The number of bytes that should be parsed for SizeT, either 4 or 8</param> /// <param name="layouts">The layout manager that will hold the new layout</param> /// <remarks> /// SizeT reuses the existing parsing logic for either uint or ulong depending on size. The ILayoutManager /// is expected to already have the relevant type's layout defined before calling this method. /// </remarks> public static LayoutManager AddSizeT(this LayoutManager layouts, int size) { if (size == 4) { layouts.AddLayout(new UInt32SizeTLayout(layouts.GetLayout <uint>())); } else if (size == 8) { layouts.AddLayout(new UInt64SizeTLayout(layouts.GetLayout <ulong>())); } else { throw new ArgumentException("Size must be 4 or 8"); } return(layouts); }
/// <summary> /// Adds supports for reading bool, sbyte, byte, char, short, ushort, int, uint, long, ulong, float, and double /// </summary> /// <param name="layouts">The layout manager that will hold the new layout</param> /// <param name="isBigEndian">True if the primitives should be read in big endian byte order, otherwise little endian</param> public static LayoutManager AddPrimitives(this LayoutManager layouts, bool isBigEndian = false) { layouts.AddLayout(new BoolLayout(typeof(bool), isBigEndian)); layouts.AddLayout(new Int8Layout(typeof(sbyte), isBigEndian)); layouts.AddLayout(new UInt8Layout(typeof(byte), isBigEndian)); layouts.AddLayout(new CharLayout(typeof(char), isBigEndian)); layouts.AddLayout(new Int16Layout(typeof(short), isBigEndian)); layouts.AddLayout(new UInt16Layout(typeof(ushort), isBigEndian)); layouts.AddLayout(new Int32Layout(typeof(int), isBigEndian)); layouts.AddLayout(new UInt32Layout(typeof(uint), isBigEndian)); layouts.AddLayout(new Int64Layout(typeof(long), isBigEndian)); layouts.AddLayout(new UInt64Layout(typeof(ulong), isBigEndian)); layouts.AddLayout(new SingleLayout(typeof(float), isBigEndian)); layouts.AddLayout(new DoubleLayout(typeof(double), isBigEndian)); return(layouts); }
/// <summary> /// Add support for parsing null terminated strings as System.String /// </summary> /// <param name="layouts">The layout manager that will hold the new layout</param> /// <param name="encoding">The encoding used to parse string characters. Currently only UTF8 and ASCII are supported</param> public static LayoutManager AddNullTerminatedString(this LayoutManager layouts, Encoding encoding) { layouts.AddLayout(new NullTerminatedStringLayout(encoding)); return(layouts); }