readCodeUnit method

BinaryCodeUnit readCodeUnit(
  1. Uint8List bytes, {
  2. String? id,
  3. String? namespace,
})

Decodes bytes into a CodeUnit whose root is already populated.

Handing the result to ApolloVM.loadCodeUnit registers it without going near a parser: that method only parses when root is null.

id and namespace override what the image recorded, for re-homing a cached unit.

Implementation

BinaryCodeUnit readCodeUnit(
  Uint8List bytes, {
  String? id,
  String? namespace,
}) {
  var decoded = _read(bytes);
  var info = decoded.info;

  var codeUnit = BinaryCodeUnit(
    info.language,
    bytes,
    id: id ?? info.codeUnitId,
    namespace: namespace ?? info.namespace,
  );
  codeUnit.root = decoded.root;
  return codeUnit;
}