2023-07-19 00:09:57 -04:00
|
|
|
import 'dart:typed_data';
|
|
|
|
|
2023-07-26 14:20:29 -04:00
|
|
|
import 'package:protobuf/protobuf.dart';
|
|
|
|
|
2023-07-19 00:09:57 -04:00
|
|
|
Future<Uint8List> protobufUpdateBytes<T extends GeneratedMessage>(
|
|
|
|
T Function(List<int>) fromBuffer,
|
|
|
|
Uint8List oldBytes,
|
|
|
|
Future<T> Function(T) update) async {
|
2023-07-26 14:20:29 -04:00
|
|
|
final oldObj = fromBuffer(oldBytes);
|
|
|
|
final newObj = await update(oldObj);
|
2023-07-19 00:09:57 -04:00
|
|
|
return Uint8List.fromList(newObj.writeToBuffer());
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Uint8List> Function(Uint8List)
|
|
|
|
protobufUpdate<T extends GeneratedMessage>(
|
2023-07-26 17:42:11 -04:00
|
|
|
T Function(List<int>) fromBuffer, Future<T> Function(T) update) =>
|
|
|
|
(oldBytes) => protobufUpdateBytes(fromBuffer, oldBytes, update);
|