-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support loading/saving older data center format versions.
Also moved a couple of sanity checks out of strict mode to prevent unexpected exception types in some cases. Closes #19.
- Loading branch information
Showing
33 changed files
with
511 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
namespace Vezel.Novadrop.Buffers; | ||
|
||
internal ref struct SpanReader | ||
{ | ||
private ReadOnlySpan<byte> _remaining; | ||
|
||
public SpanReader(ReadOnlySpan<byte> span) | ||
{ | ||
_remaining = span; | ||
} | ||
|
||
public void Advance(int count) | ||
{ | ||
_remaining = _remaining[count..]; | ||
} | ||
|
||
public void Read(scoped Span<byte> buffer) | ||
{ | ||
_remaining.CopyTo(buffer); | ||
|
||
Advance(buffer.Length); | ||
} | ||
|
||
public byte ReadByte() | ||
{ | ||
var result = _remaining[0]; | ||
|
||
Advance(sizeof(byte)); | ||
|
||
return result; | ||
} | ||
|
||
public sbyte ReadSByte() | ||
{ | ||
return (sbyte)ReadByte(); | ||
} | ||
|
||
public ushort ReadUInt16() | ||
{ | ||
var result = BinaryPrimitives.ReadUInt16LittleEndian(_remaining); | ||
|
||
Advance(sizeof(ushort)); | ||
|
||
return result; | ||
} | ||
|
||
public short ReadInt16() | ||
{ | ||
return (short)ReadUInt16(); | ||
} | ||
|
||
public uint ReadUInt32() | ||
{ | ||
var result = BinaryPrimitives.ReadUInt32LittleEndian(_remaining); | ||
|
||
Advance(sizeof(uint)); | ||
|
||
return result; | ||
} | ||
|
||
public int ReadInt32() | ||
{ | ||
return (int)ReadUInt32(); | ||
} | ||
|
||
public ulong ReadUInt64() | ||
{ | ||
var result = BinaryPrimitives.ReadUInt64LittleEndian(_remaining); | ||
|
||
Advance(sizeof(ulong)); | ||
|
||
return result; | ||
} | ||
|
||
public long ReadInt64() | ||
{ | ||
return (long)ReadUInt64(); | ||
} | ||
|
||
public float ReadSingle() | ||
{ | ||
return Unsafe.BitCast<uint, float>(ReadUInt32()); | ||
} | ||
|
||
public double ReadDouble() | ||
{ | ||
return Unsafe.BitCast<ulong, double>(ReadUInt64()); | ||
} | ||
|
||
public char ReadChar() | ||
{ | ||
return (char)ReadUInt16(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
namespace Vezel.Novadrop.Buffers; | ||
|
||
internal ref struct SpanWriter | ||
{ | ||
private Span<byte> _remaining; | ||
|
||
public SpanWriter(Span<byte> span) | ||
{ | ||
_remaining = span; | ||
} | ||
|
||
public void Advance(int count) | ||
{ | ||
_remaining = _remaining[count..]; | ||
} | ||
|
||
public void Write(scoped ReadOnlySpan<byte> buffer) | ||
{ | ||
buffer.CopyTo(_remaining); | ||
|
||
Advance(buffer.Length); | ||
} | ||
|
||
public void WriteByte(byte value) | ||
{ | ||
_remaining[0] = value; | ||
|
||
Advance(sizeof(byte)); | ||
} | ||
|
||
public void WriteSByte(sbyte value) | ||
{ | ||
WriteByte((byte)value); | ||
} | ||
|
||
public void WriteUInt16(ushort value) | ||
{ | ||
BinaryPrimitives.WriteUInt16LittleEndian(_remaining, value); | ||
|
||
Advance(sizeof(ushort)); | ||
} | ||
|
||
public void WriteInt16(short value) | ||
{ | ||
WriteUInt16((ushort)value); | ||
} | ||
|
||
public void WriteUInt32(uint value) | ||
{ | ||
BinaryPrimitives.WriteUInt32LittleEndian(_remaining, value); | ||
|
||
Advance(sizeof(uint)); | ||
} | ||
|
||
public void WriteInt32(int value) | ||
{ | ||
WriteUInt32((uint)value); | ||
} | ||
|
||
public void WriteUInt64(ulong value) | ||
{ | ||
BinaryPrimitives.WriteUInt64LittleEndian(_remaining, value); | ||
|
||
Advance(sizeof(ulong)); | ||
} | ||
|
||
public void WriteInt64(long value) | ||
{ | ||
WriteUInt64((ulong)value); | ||
} | ||
|
||
public void WriteSingle(float value) | ||
{ | ||
WriteUInt32(Unsafe.BitCast<float, uint>(value)); | ||
} | ||
|
||
public void WriteDouble(double value) | ||
{ | ||
WriteUInt64(Unsafe.BitCast<double, ulong>(value)); | ||
} | ||
|
||
public void WriteChar(char value) | ||
{ | ||
WriteUInt16(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Vezel.Novadrop.Data; | ||
|
||
public enum DataCenterArchitecture | ||
{ | ||
X86, | ||
X64, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Vezel.Novadrop.Data; | ||
|
||
public enum DataCenterFormat | ||
{ | ||
V3, | ||
V6X86, | ||
V6X64, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.