jaguar_serializer_protobuf 2.2.2 copy "jaguar_serializer_protobuf: ^2.2.2" to clipboard
jaguar_serializer_protobuf: ^2.2.2 copied to clipboard

Protobuf support for Jaguar serializer. Provides CodecRepo and SerializerRepo.

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"}');
0
likes
40
pub points
0%
popularity

Publisher

unverified uploader

Protobuf support for Jaguar serializer. Provides CodecRepo and SerializerRepo.

Repository (GitHub)
View/report issues

License

BSD-3-Clause (LICENSE)

Dependencies

jaguar_serializer, protobuf

More

Packages that depend on jaguar_serializer_protobuf