veilidchat/lib/tools/protobuf_tools.dart
Christien Rioux 9fa1666e8b lint cleanup
2023-07-26 17:42:11 -04:00

18 lines
612 B
Dart

import 'dart:typed_data';
import 'package:protobuf/protobuf.dart';
Future<Uint8List> protobufUpdateBytes<T extends GeneratedMessage>(
T Function(List<int>) fromBuffer,
Uint8List oldBytes,
Future<T> Function(T) update) async {
final oldObj = fromBuffer(oldBytes);
final newObj = await update(oldObj);
return Uint8List.fromList(newObj.writeToBuffer());
}
Future<Uint8List> Function(Uint8List)
protobufUpdate<T extends GeneratedMessage>(
T Function(List<int>) fromBuffer, Future<T> Function(T) update) =>
(oldBytes) => protobufUpdateBytes(fromBuffer, oldBytes, update);