yet_another_json_isolate 3.0.0-dev.2 copy "yet_another_json_isolate: ^3.0.0-dev.2" to clipboard
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.


Supabase Logo

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.

pub package pub test

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.

15
likes
160
points
881k
downloads

Documentation

API reference

Publisher

verified publishersupabase.io

Weekly Downloads

Package for JSON parsing off the main isolate, processing small payloads inline and large payloads on short lived isolates without copying results.

Homepage
Repository (GitHub)
View/report issues

Topics

#json #isolate #parsing #async

License

MIT (license)

More

Packages that depend on yet_another_json_isolate