yet_another_json_isolate 3.0.0-dev.2
yet_another_json_isolate: ^3.0.0-dev.2 copied to clipboard
Package for JSON parsing off the main isolate, processing small payloads inline and large payloads on short lived isolates without copying results.
yet_another_json_isolate
JSON parsing that never blocks the main isolate for long: small payloads are processed inline, large payloads on short lived isolates that hand their result back without copying.
Usage #
final isolate = YAJsonIsolate();
// serialize to a JSON string
final requestBody = await isolate.encode(requestObject);
// deserialize a JSON string
final json = await isolate.decode(responseBody);
// deserialize UTF-8 encoded JSON bytes, such as an HTTP response body,
// without materializing the intermediate string on the calling isolate
final data = await isolate.decodeBytes(response.bodyBytes);
// dispose when no longer needed
isolate.dispose();
AsyncJsonCodec #
YAJsonIsolate implements AsyncJsonCodec, the interface the Supabase clients accept
through their jsonCodec parameter. Implement it to process their JSON some other way, for
example with a native parser, or to wrap the default implementation and measure it.
class TimedJsonCodec implements AsyncJsonCodec {
TimedJsonCodec(this._inner);
final AsyncJsonCodec _inner;
@override
Future<dynamic> decode(String json) => _time(() => _inner.decode(json));
@override
Future<dynamic> decodeBytes(Uint8List encodedJson) =>
_time(() => _inner.decodeBytes(encodedJson));
@override
Future<String> encode(Object? json) => _time(() => _inner.encode(json));
@override
Future<void> dispose() => _inner.dispose();
}
License #
This repo is licensed under MIT.