jaguar_serializer_protobuf 2.2.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 35

Pub Build Status Gitter

jaguar_serializer_protobuf #

Protobuf support for jaguar_serializer

Getting Started #

Install #

#pubspec.yaml
dependencies:
  jaguar_serializer_protobuf: 

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();
  data.id = 1;
  data.name = 'name';
  data.email = 'name@email.com';
List<int> data = serializerRepo.to(person)  

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": "name@email.com"}');

Changelog #

2.2.1 #

  • Implemented ProtoCodecRepo
  • Implemented ProtoSerializerRepo

example/main.dart

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

import 'test.pb.dart';

main() {
  Person data = Person();
  data.id = 1;
  data.name = 'name';
  data.email = 'name@email.com';

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

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

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

  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": "name@email.com"}');

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

Use this package as a library

1. Depend on it

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


dependencies:
  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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
23
Health:
Code health derived from static analysis. [more]
31
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
35
Learn more about scoring.

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

  • Dart: 2.6.0
  • pana: 0.12.21

Platforms

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 (getByType), ProtoSerializerRepo.getByType (getByType).

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 (getByType), ProtoSerializerRepo.getByType (getByType).

line 94 col 16: '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 (getByType), ProtoSerializerRepo.getByType (getByType).

Support latest dependencies. (-10 points)

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

Dependencies

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 1.0.1
Transitive dependencies
fixnum 0.10.11