fromXml method
Implementation
LSLStreamInfoWithMetadata fromXml(String xml) {
final Pointer<Char> xmlPtr = xml
.toNativeUtf8(allocator: allocate)
.cast<Char>();
final lsl_streaminfo streamInfo = lsl_streaminfo_from_xml(xmlPtr);
if (streamInfo.isNullPointer) {
throw LSLException('Failed to create stream info from XML');
}
// now we have to check the "name" field. If it starts with "(invalid: "
// then there was an error, unfortunately LSL doesn't return a null pointer
// on exception in the c++ code, so we have to check the name field
final Pointer<Char> namePtr = lsl_get_name(streamInfo);
if (namePtr.isNullPointer) {
lsl_destroy_streaminfo(streamInfo);
throw LSLException('Failed to create stream info from XML: $xml');
}
final String name = namePtr.cast<Utf8>().toDartString();
if (name.startsWith('(invalid: ')) {
lsl_destroy_streaminfo(streamInfo);
throw LSLException(
'Failed to create stream info from XML: $xml, error: $name',
);
}
return LSLStreamInfoWithMetadata.fromStreamInfo(streamInfo);
}