cookStamp function

String cookStamp(
  1. Uint8List source,
  2. ModelImportSettings settings
)

A short fingerprint of source and settings: a cooked model made from both carries it (CookedModel.stampOf), so a tool can tell when it needs cooking again.

Implementation

String cookStamp(Uint8List source, ModelImportSettings settings) {
  // FNV-1a, 32 bits, over the file and the settings as saved.
  var h = 0x811C9DC5;
  void eat(List<int> bytes) {
    for (final b in bytes) {
      h ^= b;
      h = (h * 0x01000193) & 0xFFFFFFFF;
    }
  }

  eat(source);
  eat(utf8.encode(jsonEncode(settings.toJson())));
  return '${source.length.toRadixString(16)}-${h.toRadixString(16).padLeft(8, '0')}';
}