64 lines
1.6 KiB
C#
64 lines
1.6 KiB
C#
using System;
|
|
using System.Runtime.CompilerServices;
|
|
namespace ln.objects.catalog
|
|
{
|
|
public class ODBLong : ODBValue
|
|
{
|
|
public ODBLong(long value)
|
|
: base(0x12, value)
|
|
{ }
|
|
|
|
public override byte[] Serialize() => BitConverter.GetBytes((long)Value);
|
|
|
|
protected override int compare(ODBEntity other)
|
|
{
|
|
long a, b;
|
|
a = (long)Value;
|
|
b = (long)(other as ODBValue).Value;
|
|
|
|
long d = a - b;
|
|
if (d == 0)
|
|
return 0;
|
|
if (d < 0)
|
|
return -1;
|
|
return 1;
|
|
}
|
|
|
|
public static implicit operator DateTime(ODBLong l) => DateTimeOffset.FromUnixTimeMilliseconds((long)l.Value).DateTime;
|
|
public static implicit operator TimeSpan(ODBLong l) => TimeSpan.FromMilliseconds((long)l.Value);
|
|
|
|
|
|
static ODBLong()
|
|
{
|
|
RegisterDeserializer(0x12, (b, o, l) => new ODBLong(BitConverter.ToInt64(b, o)));
|
|
}
|
|
|
|
}
|
|
|
|
public class ODBULong : ODBValue
|
|
{
|
|
public ODBULong(ulong value)
|
|
: base(0x13, value)
|
|
{ }
|
|
|
|
public override byte[] Serialize() => BitConverter.GetBytes((ulong)Value);
|
|
protected override int compare(ODBEntity other)
|
|
{
|
|
ulong a = (ulong)Value;
|
|
ulong b = (ulong)(other as ODBValue).Value;
|
|
|
|
if (a == b)
|
|
return 0;
|
|
if (a < b)
|
|
return -1;
|
|
return 1;
|
|
}
|
|
|
|
static ODBULong()
|
|
{
|
|
RegisterDeserializer(0x13, (b, o, l) => new ODBULong(BitConverter.ToUInt64(b, o)));
|
|
}
|
|
|
|
}
|
|
}
|