fix(core): Cleans up serialization (#606)

This commit is contained in:
Kamron Batman 2021-05-16 13:45:32 -07:00 committed by GitHub
parent 8418d4a7db
commit cb66bef0e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 177 additions and 218 deletions

View file

@ -15,7 +15,6 @@
using System;
using System.IO;
using System.Net;
namespace Server
{
@ -35,14 +34,6 @@ namespace Server
return intern ? Utility.Intern(str) : str;
}
public DateTime ReadDateTime() => new(_reader.ReadInt64(), DateTimeKind.Utc);
public TimeSpan ReadTimeSpan() => new(_reader.ReadInt64());
public DateTime ReadDeltaTime() => new(_reader.ReadInt64() + DateTime.UtcNow.Ticks, DateTimeKind.Utc);
public decimal ReadDecimal() => _reader.ReadDecimal();
public long ReadLong() => _reader.ReadInt64();
public ulong ReadULong() => _reader.ReadUInt64();
@ -65,43 +56,6 @@ namespace Server
public bool ReadBool() => _reader.ReadBoolean();
public int ReadEncodedInt()
{
int v = 0, shift = 0;
byte b;
do
{
b = _reader.ReadByte();
v |= (b & 0x7F) << shift;
shift += 7;
}
while (b >= 0x80);
return v;
}
public IPAddress ReadIPAddress()
{
byte length = ReadByte();
// Either 2 ushorts, or 8 ushorts
Span<byte> integer = stackalloc byte[length];
Read(integer);
return Utility.Intern(new IPAddress(integer));
}
public Point3D ReadPoint3D() => new(ReadInt(), ReadInt(), ReadInt());
public Point2D ReadPoint2D() => new(ReadInt(), ReadInt());
public Rectangle2D ReadRect2D() => new(ReadPoint2D(), ReadPoint2D());
public Rectangle3D ReadRect3D() => new(ReadPoint3D(), ReadPoint3D());
public Map ReadMap() => Map.Maps[ReadByte()];
public Race ReadRace() => Race.Races[ReadByte()];
public int Read(Span<byte> buffer) => _reader.Read(buffer);
public long Seek(long offset, SeekOrigin origin) => _reader.BaseStream.Seek(offset, origin);