internal static void GetValueFromData(GXDLMSSettings settings, GXReplyData reply)
{
GXByteBuffer data = reply.Data;
GXDataInfo info = new GXDataInfo();
if (reply.Value is Object[])
{
info.Type = DataType.Array;
info.Count = reply.TotalCount;
info.Index = reply.Count;
}
int index = data.Position;
data.Position = reply.ReadPosition;
try
{
Object value = GXCommon.GetData(settings, data, info);
if (value != null)
{
lock (reply)
{
// If new data.
if (!(value is Object[]))
{
reply.DataType = info.Type;
reply.Value = value;
reply.TotalCount = 0;
reply.ReadPosition = data.Position;
}
else
{
if (((Object[])value).Length != 0)
{
if (reply.Value == null)
{
reply.Value = value;
}
else
{
// Add items to collection.
List<Object> list = new List<Object>();
list.AddRange((Object[])reply.Value);
list.AddRange((Object[])value);
reply.Value = list.ToArray();
}
}
reply.ReadPosition = data.Position;
// Element count.
reply.TotalCount = info.Count;
}
}
}
else if (info.Complete
&& reply.Command == Command.DataNotification)
{
// If last item is null. This is a special case.
reply.ReadPosition = data.Position;
}
}
finally
{
data.Position = index;
}
// If last data frame of the data block is read.
if (reply.Command != Command.DataNotification
&& info.Complete && reply.MoreData == RequestTypes.None)
{
// If all blocks are read.
settings.ResetBlockIndex();
data.Position = 0;
}
}