decodeAdvance method
Implementation
RitoBackgroundAdvance decodeAdvance(Uint8List bytes) {
final reader = openRitoWireMessage(
bytes,
magic: 'RITOBGA1',
label: 'background advance',
);
final state = _state(reader);
final intentRequestId = reader.externalId('intent request id');
final replacesArtifactId = reader.externalId('replaces artifact id');
final movesVisibleContent = reader.boolean(
'background moves visible content',
);
final artifactBytes = reader.blobView('background artifact');
// Complete may carry exactly one artifact: the completion handoff
// that delivers the book page count to a reader who never turned a
// page. Indexing and candidatePending carry nothing by definition.
if ((state == RitoBackgroundState.candidatePending ||
state == RitoBackgroundState.indexing) &&
artifactBytes.isNotEmpty) {
reader.fail('$state background advance must not carry an artifact');
}
final artifact = artifactBytes.isEmpty
? null
: artifactDecoder.decode(artifactBytes);
reader.finish('background advance wire message');
return RitoBackgroundAdvance(
state: state,
intentRequestId: intentRequestId,
replacesArtifactId: replacesArtifactId,
movesVisibleContent: movesVisibleContent && artifact != null,
artifact: artifact,
);
}