composeStructure static method

DC composeStructure(
  1. Structure value,
  2. DistributedConnection connection, [
  3. bool includeKeys = true,
  4. bool includeTypes = true,
  5. bool prependLength = false,
])
Compose a structure into an array of bytes Structure to compose DistributedConnection is required in case an item in the structure is at the other end Whether to include the structure keys Whether to include each item DataType If true, prepend the length as UInt32 at the beginning of the returned bytes array

Implementation

static DC composeStructure(Structure value, DistributedConnection connection,
    [bool includeKeys = true,
    bool includeTypes = true,
    bool prependLength = false]) {
  var rt = new BinaryList();

  if (includeKeys) {
    for (var k in value.keys) {
      var key = DC.stringToBytes(k);
      rt
        ..addUint8(key.length)
        ..addDC(key)
        ..addDC(compose(value[k], connection));
    }
  } else {
    for (var k in value.keys)
      rt.addDC(compose(value[k], connection, includeTypes));
  }

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

  return rt.toDC(); //.toArray();
}