Persistence class Null safety
The Persistence class should be used as a singleton (call Persistence.get) that can write and potentially read GpsPointsView instances to StreamSink respectively from Stream instances. Reading from streams requires the view to be modifiable, which not all views are.
The class relies on Persister subclasses, that are registered with it as supporting particular subclasses of GpsPointsView, to do the actual streaming conversions. These Persister instances must therefore be registered by the users of this library at runtime before trying to load/store data.
The persisted format is structured as follows:
- 100 bytes: Header, consisting of:
- 20 bytes: signature to recognize that this is indeed a file stored by the library. Default value may be overridden.
- 2 bytes: Uint16 indicating the version number of the streaming method. This is independent of the versioning of the persisted data. Persistence will not read files that have a streaming method version newer than its own, thus ensuring that older versions don't crash or read incorrectly files that are written in a newer format.
- 20 bytes: Persister signature header to recognize data type. Each registered Persister instance must have a unique signature. This will be validated at reading time against the Persister registered for the data currently being read.
- 2 bytes: Uint16 indicating the version number of the persisted data, so that upgrades in format are possible and recognizable without changing the header. Persistence will not read files that have a persisted data version newer than the one supported by the relevant registered Persister. Again, this ensures old versions don't try to read new data and do so badly.
- 1 byte: the number of bytes to be read from the following metadata sub-stream
- 55 bytes: reserved for any kind of metadata a particular Persister may require.
- unknown number of bytes: the streamed data. By having a fixed header size, we can determine numbers of points in a file without fully parsing it, by simply looking at the total file size minus the header and dividing the outcome by the storage size per point.
- hashCode → int
The hash code for this object.
- maxMetadataLength → int
The maximum number of bytes allowed for the metadata of a Persister.
Changing this requires changing the version number of the Persistence as
well as compatibility/conversion code for reading older versions.
- runtimeType → Type
A representation of the runtime type of the object.
GpsPointsView< GpsPoint>view) → Persister
Returns the Persister registered to handled objects of the type of
viewor raises NoPersisterException if not found.
Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
GpsPointsView< GpsPoint>view, Stream< List<sourceStream, [int? streamSizeBytesHint]) → Future< int>> void>
Overwrites the contents of
viewwith data read from
sourceStream. Optionally a non-null
streamSizeBytesHintmay be provided to indicate how large the stream is, but see caveats in StreamReaderState.remainingStreamBytesHint on its use.
Persister persister) → Persister
Registers the specified
persisteras supporting its
persister.supportedType, and returns
) → String
A string representation of this object.
Persister persister) → void
Unregisters the specified
GpsPointsView< GpsPoint>view, StreamSink< List<targetSink) → Future< int>> void>
targetSinkin binary format.