decodeWebGlSection function
The sources in bytes.
Throws BundleSectionFormatException when the bytes are not the document above — the device turns that into a refusal naming the bundle.
Implementation
WebGlSectionSources decodeWebGlSection(ByteData bytes) {
final document = decodeSectionJson(bytes);
if (document is! Map<String, dynamic>) {
throw const BundleSectionFormatException(
'the section is not a JSON object',
);
}
Map<String, String> stages(String kind) {
final entries = document[kind];
if (entries is! Map<String, dynamic>) {
throw BundleSectionFormatException('the section has no "$kind" object');
}
return <String, String>{
for (final entry in entries.entries)
entry.key: switch (entry.value) {
final String source => source,
_ => throw BundleSectionFormatException(
'"${entry.key}" under "$kind" is not a source string',
),
},
};
}
return (vertex: stages('vertex'), fragment: stages('fragment'));
}