decodeSelectorBytes function
- Uint8List bytes
Decode a selector from either DAG-CBOR or DAG-JSON bytes.
The encoding is detected from the first non-whitespace byte.
Implementation
Future<Selector> decodeSelectorBytes(Uint8List bytes) async {
final trimmed = _trimLeading(bytes);
if (trimmed.isEmpty) {
throw SelectorParseError('Empty selector bytes');
}
final first = trimmed.first;
// DAG-JSON objects start with '{'; DAG-JSON arrays start with '['.
if (first == 0x7b || first == 0x5b) {
return decodeSelectorDagJson(bytes);
}
return decodeSelectorDagCbor(bytes);
}