composeStructureArray static method

DC composeStructureArray(
  1. List<Structure>? structures,
  2. DistributedConnection connection, [
  3. bool prependLength = false
])
Compose an array of structures into an array of bytes Array of Structure to compose DistributedConnection is required in case a structure in the array holds items at the other end If true, prepend the length as UInt32 at the beginning of the returned bytes array

Implementation

static DC composeStructureArray(
    List<Structure>? structures, DistributedConnection connection,
    [bool prependLength = false]) {
  if (structures == null || structures.length == 0)
    return prependLength ? new DC(4) : new DC(0);

  var rt = new BinaryList();
  var comparsion = StructureComparisonResult.Structure;

  rt
    ..addUint8(comparsion)
    ..addDC(composeStructure(structures[0], connection, true, true, true));

  for (var i = 1; i < structures.length; i++) {
    comparsion =
        compareStructures(structures[i - 1], structures[i], connection);
    rt.addUint8(comparsion);

    if (comparsion == StructureComparisonResult.Structure)
      rt.addDC(composeStructure(structures[i], connection, true, true, true));
    else if (comparsion == StructureComparisonResult.StructureSameKeys)
      rt.addDC(
          composeStructure(structures[i], connection, false, true, true));
    else if (comparsion == StructureComparisonResult.StructureSameTypes)
      rt.addDC(
          composeStructure(structures[i], connection, false, false, true));
  }

  if (prependLength) rt.insertInt32(0, rt.length);

  return rt.toDC();
}