parseHistory static method

AsyncReply<KeyList<PropertyTemplate, List<PropertyValue>>> parseHistory(
  1. DC data,
  2. int offset,
  3. int length,
  4. IResource resource,
  5. DistributedConnection connection,
)
Parse resource history Array of bytes. Zero-indexed offset. Number of bytes to parse. Resource Starting age. Ending age. DistributedConnection is required to fetch resources.

Implementation

static AsyncReply<KeyList<PropertyTemplate, List<PropertyValue>>>
    parseHistory(DC data, int offset, int length, IResource resource,
        DistributedConnection connection) {
  var list = <
      PropertyTemplate>[]; //new KeyList<PropertyTemplate, List<PropertyValue>?>();

  var reply =
      new AsyncReply<KeyList<PropertyTemplate, List<PropertyValue>>>();

  var bagOfBags = new AsyncBag<List<PropertyValue>>();

  var ends = offset + length;

  //var sizeObject = new SizeObject();

  while (offset < ends) {
    var index = data[offset++];
    var pt = resource.instance?.template.getPropertyTemplateByIndex(index);
    if (pt != null) {
      list.add(pt); //, null);
      var cs = data.getUint32(offset);
      offset += 4;
      bagOfBags.add(parsePropertyValueArray(data, offset, cs, connection));
      offset += cs;
    }
  }

  bagOfBags.seal();

  bagOfBags.then((x) {
    var keyList = KeyList<PropertyTemplate, List<PropertyValue>>();

    for (var i = 0; i < list.length; i++) keyList.add(list[i], x[i]);

    //list[list.keys.elementAt(i)] = x[i];

    reply.trigger(keyList);
  });

  return reply;
}