mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2026-06-13 14:38:43 +00:00
98 lines
2.2 KiB
C#
98 lines
2.2 KiB
C#
using Esiur.Data.Types;
|
|
using Esiur.Protocol;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace Esiur.Data
|
|
{
|
|
public class TruPrimitive:Tru
|
|
{
|
|
Type _runtimeType;
|
|
|
|
public override Type RuntimeType => _runtimeType;
|
|
|
|
public override string ToString()
|
|
{
|
|
return Identifier.ToString() + (Nullable ? "?" : "");
|
|
}
|
|
|
|
public TruPrimitive(TruIdentifier identifier, bool nullable, Type type)
|
|
{
|
|
Identifier = identifier;
|
|
Nullable = nullable;
|
|
_runtimeType = type;
|
|
}
|
|
|
|
public override void SetNull(List<byte> flags)
|
|
{
|
|
if (RefTypes.Contains(Identifier))
|
|
{
|
|
Nullable = (flags.FirstOrDefault() == 2);
|
|
if (flags.Count > 0)
|
|
flags.RemoveAt(0);
|
|
}
|
|
}
|
|
|
|
|
|
public override void SetNull(byte flag)
|
|
{
|
|
if (RefTypes.Contains(Identifier))
|
|
{
|
|
Nullable = (flag == 2);
|
|
}
|
|
}
|
|
|
|
public override void SetNotNull(List<byte> flags)
|
|
{
|
|
if (RefTypes.Contains(Identifier))
|
|
{
|
|
Nullable = (flags.FirstOrDefault() != 1);
|
|
if (flags.Count > 0)
|
|
flags.RemoveAt(0);
|
|
}
|
|
}
|
|
|
|
public override void SetNotNull(byte flag)
|
|
{
|
|
if (RefTypes.Contains(Identifier))
|
|
{
|
|
Nullable = (flag != 1);
|
|
}
|
|
}
|
|
|
|
public override bool Match(Tru other)
|
|
{
|
|
|
|
if (other is TruPrimitive otherComposite)
|
|
{
|
|
if (other.Identifier != Identifier)
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public override byte[] Compose(EpConnection connection)
|
|
{
|
|
var rt = new BinaryList();
|
|
|
|
if (Nullable)
|
|
rt.AddUInt8((byte)(0x80 | (byte)Identifier));
|
|
else
|
|
rt.AddUInt8((byte)Identifier);
|
|
|
|
return rt.ToArray();
|
|
|
|
}
|
|
|
|
public override Tru ToNullable()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
}
|
|
}
|