serialize method
Implementation
Uint8List serialize() {
if (intentToAdd || skipWorkTree) {
throw Exception('Index Entry version not supported');
}
var writer = ByteDataWriter(endian: Endian.big);
cTime = cTime.toUtc();
writer.writeUint32(cTime.millisecondsSinceEpoch ~/ 1000);
writer.writeUint32((cTime.millisecond * 1000 + cTime.microsecond) * 1000);
mTime = mTime.toUtc();
writer.writeUint32(mTime.millisecondsSinceEpoch ~/ 1000);
writer.writeUint32((mTime.millisecond * 1000 + mTime.microsecond) * 1000);
writer.writeUint32(dev);
writer.writeUint32(ino);
writer.writeUint32(mode.val);
writer.writeUint32(uid);
writer.writeUint32(gid);
writer.writeUint32(fileSize);
writer.write(hash.bytes);
var flags = (stage.val & 0x3) << 12;
const nameMask = 0xfff;
var pathUtf8 = utf8.encode(path);
if (pathUtf8.length < nameMask) {
flags |= pathUtf8.length;
} else {
flags |= nameMask;
}
writer.writeUint16(flags);
writer.write(pathUtf8); // This is a problem!
// Add padding
const entryHeaderLength = 62;
var wrote = entryHeaderLength + pathUtf8.length;
var padLen = 8 - wrote % 8;
writer.write(Uint8List(padLen));
return writer.toBytes();
}