parseFunctionJson function
Strict, bounded JSON before ordinary decoding can discard duplicate keys.
Implementation
Object? parseFunctionJson(
Uint8List bytes, {
int maxBytes = 2097152,
int maxDepth = 12,
}) {
if (maxDepth < 1 || maxDepth > 64) {
throw ArgumentError.value(maxDepth, 'maxDepth');
}
if (maxBytes < 1 || maxBytes > 9437184 || bytes.length > maxBytes) {
throw const FormatException('JSON exceeds its byte limit.');
}
// Dart's UTF-8 codec strips a BOM. The wire contract rejects one.
if (bytes.length >= 3 &&
bytes[0] == 239 &&
bytes[1] == 187 &&
bytes[2] == 191) {
throw const FormatException('JSON must not contain a BOM.');
}
return _Parser(utf8.decode(bytes), maxDepth).parse();
}