Binary reader and writer that supports different endian types.
$ dotnet add package Snowberry.IOA binary reader and writer that supports different endian types.
Reader
ReadCString).ReadSizedCString).ReadString).ReadLine).Sha1 type.Writer
WriteCString).WriteSizedCString).Sha1 type.WriteLine).Custom Sha1 type based on SHA-1.
| Name | Description |
|---|---|
| Reader | |
| BaseEndianReader | The abstract base type that implements the IEndianReader interface. |
| EndianStreamReader | Used for reading from streams, inherits the BaseEndianReader type. |
| Writer | |
| EndianStreamWriter | Used for writing into streams, inherits the BinaryWriter type and implements the IEndianWriter interface. |
var stream = new MemoryStream();
using var writer = new EndianStreamWriter(stream, keepStreamOpen: true);
writer.Write(10, EndianType.BIG)
.Write(20L, EndianType.BIG)
.Write(30F, EndianType.BIG)
.Write(40u, EndianType.BIG)
.Write(50d, EndianType.BIG);
writer.BaseStream.Position = 0;
using var reader = new EndianStreamReader(stream);
_ = reader.ReadInt32(EndianType.BIG);
_ = reader.ReadInt64(EndianType.BIG);
_ = reader.ReadFloat(EndianType.BIG);
_ = reader.ReadUInt32(EndianType.BIG);
_ = reader.ReadDouble(EndianType.BIG);
The Analyzer abstract type can be inherited and used to monitor each buffer fill operation.
This is useful if a binary file is or has encrypted content.
The BinaryEndianConverter type can be used to convert data in a Span<byte> to all supported data types and also accepts an offset.
var buffer = new byte[] { ... };
int offset = ...;
var endianType = EndianType.BIG;
_ = BinaryEndianConverter.ToInt64(buffer, endianType);
_ = BinaryEndianConverter.ToInt64(buffer, offset, endianType);
| Type | Endian type(s) |
|---|---|
| Int8 | - |
| UInt8 | - |
| Int16 | Little, Big |
| UInt16 | Little, Big |
| Int32 | Little, Big |
| UInt32 | Little, Big |
| Int64 | Little, Big |
| UInt64 | Little, Big |
| Float | Little, Big |
| Double | Little, Big |
| Guid | Little, Big |
| Sha1 | Little |