getMeshFromHash function
A function that decodes a hash string generated by getHashFromMesh back into a mesh gradient.
The hash is a base64 encoded string that contains the compressed binary
representation of the mesh gradient. The hash is prefixed with OM:
to
indicate that it is an O'Mesh hash.
The hash is decoded by first removing the prefix, then adding padding to the base64 string, then decoding the base64 string into a compressed binary representation, and finally decompressing the binary data using zlib decompression.
The hash is generated by first encoding the mesh gradient into a binary format using the OMeshBinaryFormatCodec, then compressing the binary data using zlib compression, and finally encoding the compressed data into a unpadded base64 string.
Implementation
OMeshRect getMeshFromHash(String hash) {
final unprefixied = hash.substring(_kPrefix.length);
final paddedHash = _addPadding(unprefixied);
final compressed = base64Url.decode(paddedHash);
final bytes = zlib.zlibDecompress(compressed);
final layers = OMeshBinaryFormatCodec.v1.decoder.convert(
Uint8List.fromList(bytes),
);
return layers;
}