import 'dart:typed_data'; import 'dart:convert'; T jsonDecodeBytes( T Function(Map) fromJson, Uint8List data) { return fromJson(jsonDecode(utf8.decode(data))); } Uint8List jsonEncodeBytes(Object? object, {Object? Function(Object?)? toEncodable}) { return Uint8List.fromList( utf8.encode(jsonEncode(object, toEncodable: toEncodable))); } Future jsonUpdateBytes(T Function(Map) fromJson, Uint8List oldBytes, Future Function(T) update) async { T oldObj = fromJson(jsonDecode(utf8.decode(oldBytes))); T newObj = await update(oldObj); return jsonEncodeBytes(newObj); } Future Function(Uint8List) jsonUpdate( T Function(Map) fromJson, Future Function(T) update) { return (Uint8List oldBytes) { return jsonUpdateBytes(fromJson, oldBytes, update); }; } T Function(Object?) genericFromJson( T Function(Map) fromJsonMap) { return (Object? json) { return fromJsonMap(json as Map); }; }