2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-09-13 12:43:17 +00:00
This commit is contained in:
2025-08-24 05:58:40 +03:00
parent b12939e109
commit a1353a03ad
7 changed files with 92 additions and 55 deletions

View File

@@ -122,30 +122,30 @@ public static class Codec
DataDeserializer.LocalResourceParser8,
DataDeserializer.ResourceParser8,
},
new SyncParser[]{
DataDeserializer.Int16Parser,
new SyncParser[]{
DataDeserializer.UInt16Parser,
DataDeserializer.Int16Parser,
DataDeserializer.Char16Parser,
DataDeserializer.LocalResourceParser16,
DataDeserializer.ResourceParser16,
},
new SyncParser[]{
DataDeserializer.Int32Parser,
new SyncParser[]{
DataDeserializer.UInt32Parser,
DataDeserializer.Int32Parser,
DataDeserializer.Float32Parser,
DataDeserializer.LocalResourceParser32,
DataDeserializer.ResourceParser32,
},
new SyncParser[]{
DataDeserializer.Int64Parser,
new SyncParser[]{
DataDeserializer.UInt64Parser,
DataDeserializer.Int64Parser,
DataDeserializer.Float64Parser,
DataDeserializer.DateTimeParser,
},
new SyncParser[]
{
DataDeserializer.Int128Parser, // int 128
{
DataDeserializer.UInt128Parser, // uint 128
DataDeserializer.Int128Parser, // int 128
DataDeserializer.Float128Parser,
}
};

View File

@@ -114,10 +114,16 @@ public static class DataSerializer
public static (TransmissionTypeIdentifier, byte[]) EnumComposer(object value, DistributedConnection connection)
{
Console.WriteLine(value.GetType().Name);
if (value == null)
return (TransmissionTypeIdentifier.Null, new byte[0]);
var template = connection.Instance.Warehouse.GetTemplateByType(value.GetType());
var warehouse = connection?.Instance?.Warehouse ?? connection?.Server?.Instance?.Warehouse;
if (warehouse == null)
throw new Exception("Warehouse not set.");
var template = warehouse.GetTemplateByType(value.GetType());
var intVal = Convert.ChangeType(value, (value as Enum).GetTypeCode());

View File

@@ -57,6 +57,23 @@ namespace Esiur.Data
//e6 = data[offset++];
}
public unsafe override int GetHashCode()
{
unchecked
{
fixed (byte* p = Data)
{
ulong u0 = *(ulong*)p;
ulong u1 = *(ulong*)(p + 8);
// simple mixing of two 64-bit halves
return ((int)u0 ^ (int)(u0 >> 32)) ^
((int)u1 ^ (int)(u1 >> 32));
}
}
}
public UUID(byte[] data) {
if (data.Length != 16)
@@ -88,6 +105,14 @@ namespace Esiur.Data
//return $"{a1.ToString("x2")}{a2.ToString("x2")}{a3.ToString("x2")}{a4.ToString("x2")}-{b1.ToString("x2")}{b2.ToString("x2")}-{c1.ToString("x2")}{c2.ToString("x2")}-{d1.ToString("x2")}{d2.ToString("x2")}-{e1.ToString("x2")}{e2.ToString("x2")}{e3.ToString("x2")}{e4.ToString("x2")}{e5.ToString("x2")}{e6.ToString("x2")}";
}
public override bool Equals(object obj)
{
if (obj is UUID b)
return Data.SequenceEqual(b.Data);
return false;
}
public static bool operator == (UUID a, UUID b)
{
return a.Data.SequenceEqual(b.Data);