06d938046f
and TargetFlags.soundNullSafety TEST=existing Change-Id: I5e28d3d187b0f84fa23130c042fd3c55b89c687c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413460 Reviewed-by: Ömer Ağacan <omersa@google.com> Reviewed-by: Jens Johansen <jensj@google.com> Reviewed-by: Alexander Markov <alexmarkov@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Nate Biggs <natebiggs@google.com>
42 lines
1.2 KiB
Dart
42 lines
1.2 KiB
Dart
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:typed_data' show BytesBuilder, Uint8List;
|
|
|
|
import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter;
|
|
import 'package:kernel/kernel.dart';
|
|
export 'package:kernel/kernel.dart';
|
|
|
|
Library libRoundTrip(Library lib) {
|
|
return serializationRoundTrip([lib])[0];
|
|
}
|
|
|
|
List<Library> serializationRoundTrip(List<Library> libraries) {
|
|
Component c = new Component(libraries: libraries)
|
|
..setMainMethodAndMode(null, false);
|
|
Uint8List bytes = serializeComponent(c);
|
|
Component c2 = loadComponentFromBytes(bytes);
|
|
return c2.libraries;
|
|
}
|
|
|
|
Uint8List serializeComponent(Component c) {
|
|
ByteSink byteSink = new ByteSink();
|
|
BinaryPrinter printer = new BinaryPrinter(byteSink);
|
|
printer.writeComponentFile(c);
|
|
return byteSink.builder.takeBytes();
|
|
}
|
|
|
|
/// A [Sink] that directly writes data into a byte builder.
|
|
class ByteSink implements Sink<List<int>> {
|
|
final BytesBuilder builder = new BytesBuilder();
|
|
|
|
@override
|
|
void add(List<int> data) {
|
|
builder.add(data);
|
|
}
|
|
|
|
@override
|
|
void close() {}
|
|
}
|