mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2024-12-17 20:14:31 -05:00
18 lines
612 B
Dart
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);
|