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

@ -17,7 +17,6 @@ using System;
using System.Buffers.Binary;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text;
using Server.Text;
@ -52,7 +51,7 @@ namespace Server
return null;
}
var length = ReadEncodedInt();
var length = ((IGenericReader)this).ReadEncodedInt();
if (length <= 0)
{
return intern ? Utility.Intern("") : "";
@ -63,14 +62,6 @@ namespace Server
return intern ? Utility.Intern(str) : str;
}
public DateTime ReadDateTime() => new(ReadLong(), DateTimeKind.Utc);
public TimeSpan ReadTimeSpan() => new(ReadLong());
public DateTime ReadDeltaTime() => new(ReadLong() + DateTime.UtcNow.Ticks, DateTimeKind.Utc);
public decimal ReadDecimal() => new(stackalloc int[4] { ReadInt(), ReadInt(), ReadInt(), ReadInt() });
public long ReadLong()
{
var v = BinaryPrimitives.ReadInt64LittleEndian(_buffer.AsSpan(_position, 8));
@ -133,42 +124,6 @@ namespace Server
public bool ReadBool() => _buffer[_position++] != 0;
public int ReadEncodedInt()
{
int v = 0, shift = 0;
byte b;
do
{
b = 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)
{
var length = buffer.Length;