readViewFromStream method
Future<void>
readViewFromStream(
- GpsPointsView<
GpsPoint> view, - StreamReaderState source,
- int version,
- ByteData metadata,
override
Overwrites the contents of view
(if it is not read-only) with
the information fom the source
. version
and metadata
indicate
the additional information that was read from the block header in
the file, and may be used to e.g. convert old formats to new.
Implementation
@override
Future<void> readViewFromStream(GpsPointsView view, StreamReaderState source,
int version, ByteData metadata) {
return Future.sync(() async {
final gpc = view as GpcEfficient;
// Pre-allocate the capacity if possible.
gpc.capacity = source.remainingStreamBytesHint ?? gpc.capacity;
// Read data in roughly chunks, such that they're divisible by the
// expected element size.
final elementsPerChunk = chunkSize ~/ gpc.elementSizeInBytes;
// Ensure it's robust for stupid situations where the element size is
// huge: always read at least one element at a time.
final chunkSizeBytes =
gpc.elementSizeInBytes * max<int>(1, elementsPerChunk);
do {
final readData =
await source.readByteData(chunkSizeBytes, gpc.elementSizeInBytes);
if (readData.lengthInBytes == 0) {
break;
}
gpc.addByteData(readData);
} while (true);
});
}