jaguar_serializer_protobuf 2.2.2

Pub Build Status Gitter

jaguar_serializer_protobuf #

Protobuf support for jaguar_serializer

Getting Started #

Install #


Usage #

Import jaguar_serializer_protobuf

import 'package:jaguar_serializer/jaguar_serializer_protobuf.dart';

Generate your Dart model from your proto definition with proto compiler.

protoc --dart_out=. ./person.proto -I=.

Once your models are generated, you can use them like this:

final serializerRepo = ProtoSerializerRepo()
    ..add((data)=>Person.fromBuffer(data), toJson: (data)=>Person.fromJson(data));

You can then serialize like this:

Person person = Person(); = 1; = 'name'; = '';
List<int> data =  

And deserialize like this:

Person person2 = serializerRepo.from<Person>(data)

You can also enable JSON support if you need to debug your network layer. To do so use the isJsonFormatEnabled param of the repo:

final serializerJsonRepo = ProtoSerializerRepo(isJsonFormatEnabled: true)
    ..add((data)=>Person.fromBuffer(data), toJson: (data)=>Person.fromJson(data));
Person personJson = serializerJsonRepo.from<Person>('{"1": "name", "2": 1, "3": ""}');

Changelog #

2.2.1 #

  • Implemented ProtoCodecRepo
  • Implemented ProtoSerializerRepo


import 'package:collection/collection.dart';
import 'package:jaguar_serializer_protobuf/proto_repo.dart';

import 'test.pb.dart';

main() {
  Person data = Person(); = 1; = 'name'; = '';

  final List<int> buffer = data.writeToBuffer();

  final serializer = ProtoSerializerRepo()
    ..add((data) => Person.fromBuffer(data));

  dynamic person = serializer.from<Person>(buffer);
  final List<int> personData =;

  final serializerJson = ProtoSerializerRepo(isJsonFormatEnabled: true)
    ..add((data) => Person.fromBuffer(data),
        toJson: (data) => Person.fromJson(data));
  dynamic personJson = serializerJson
      .from<Person>('{"1": "name", "2": 1, "3": ""}');

  assert(const ListEquality().equals(personData, buffer));
  assert( == 'name');
  assert( == 'name');

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  jaguar_serializer_protobuf: ^2.2.2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:jaguar_serializer_protobuf/proto_repo.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19


Detected platforms:

Error(s) prevent platform classification:

Error(s) in lib/proto_repo.dart: Superinterfaces don't have a valid override for 'getByType': SerializerRepo.getByType (Serializer

Health issues and suggestions

Fix lib/proto_repo.dart. (-43.75 points)

Analysis of lib/proto_repo.dart failed with 2 errors:

line 9 col 7: Superinterfaces don't have a valid override for 'getByType': SerializerRepo.getByType (Serializer

line 94 col 3: 'ProtoSerializerRepo.getByType' ('dynamic Function(dynamic) Function(Type)') isn't a valid override of 'SerializerRepo.getByType' ('Serializer

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Error(s) prevent platform classification:

Error(s) in lib/proto_repo.dart: Superinterfaces don't have a valid override for 'getByType': SerializerRepo.getByType (Serializer

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (protobuf).


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
jaguar_serializer ^2.2.6 2.2.12
protobuf ^0.10.5 0.10.8 0.13.15
Transitive dependencies
fixnum 0.10.9