2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-12-14 00:40:26 +00:00

Deserialization fix

This commit is contained in:
2025-11-16 11:06:20 +03:00
parent e2e4ac90bc
commit d730fe1b8d
14 changed files with 571 additions and 221 deletions

View File

@@ -393,6 +393,7 @@ public static class DataSerializer
if (value == null)
return new TDU(TDUIdentifier.Null, null, 0);
//var warehouse = connection?.Instance?.Warehouse ?? connection?.Server?.Instance?.Warehouse;
//if (warehouse == null)
// throw new Exception("Warehouse not set.");
@@ -557,6 +558,23 @@ public static class DataSerializer
{
composed = GroupUInt16Codec.Encode((IList<ushort>)value);
}
else if (tru.Identifier == TRUIdentifier.Enum)
{
var rt = new List<byte>();
var template = warehouse.GetTemplateByType(tru.GetRuntimeType(warehouse));
foreach (var v in value)
{
var intVal = Convert.ChangeType(v, (v as Enum).GetTypeCode());
var ct = template.Constants.FirstOrDefault(x => x.Value.Equals(intVal));
if (ct == null)
throw new Exception("Unknown Enum.");
rt.Add(ct.Index);
}
composed = rt.ToArray();
}
else
{
var rt = new List<byte>();