jaguar_serializer_protobuf 2.2.2

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new65

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

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages 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';
  
Version Uploaded Documentation Archive
2.2.2 Jan 9, 2019 Go to the documentation of jaguar_serializer_protobuf 2.2.2 Download jaguar_serializer_protobuf 2.2.2 archive
2.2.1 Jan 9, 2019 Go to the documentation of jaguar_serializer_protobuf 2.2.1 Download jaguar_serializer_protobuf 2.2.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
29
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
65
Learn more about scoring.

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

  • Dart: 2.1.0
  • pana: 0.12.10

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in libraries.

Dependencies

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