pbconv 0.5.9

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

A implement of Dart converter for Protobuf.

Introduction #

Convert a message object to proto buffer binary bytes, Or convert proto buffer binary bytes to a message object.

Examples #

This is the encoder example.

import "dart:io";
import 'package:pbconv/pbconv.dart';

final List<Field> fields = [
  RequiredField(1, 'ID', Type.uint32),
  RequiredField(2, "Name", Type.string),
  OptionalField(3, "Email", Type.string, 'tom@example.com')
];

main() {
  var message = EncoderMessage(fields);
  message[fields[0]] = 1;
  message[fields[1]] = 'Tom';
  var proto = protobufEncode(message);
  print(proto.bytes);
  File file = File("example.bin");
  file.writeAsBytesSync(proto.bytes);
}

This is decoder example.

import "dart:io";
import 'dart:typed_data';
import 'package:pbconv/pbconv.dart';

final List<Field> fields = [
  RequiredField(1, 'ID', Type.uint32),
  RequiredField(2, "Name", Type.string),
  OptionalField(3, "Email", Type.string, 'tom@example.com')
];

main() {
  File file = File("example.bin");
  var bytes = file.readAsBytesSync();
  print(bytes);
  var message = protobufDecode(ProtoBytes(fields, bytes as Uint8List));
  print(message.toString());
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.5.9 #

All the function seem to completed, So the next, We will hard test it.

0.5.5 #

Correct the problem for publication.

0.5.4 #

  • maintance.

0.5.3 #

  • Added to support Dart:Convert.

0.5.2 #

  • Now it seems that most of the bugs have been solved.

0.5.1 #

  • Some problems have been solved, mainly those brought about by the rewriting process.

0.5.1 #

  • Conduct detailed tests to find problems.

0.5.0 #

  • Convert my protobuf library from C++ to Dart, It's the initial version for Dart version protobuf.

example/example.dart

import "dart:io";
import 'dart:typed_data';
import 'package:pbconv/pbconv.dart';

final List<Field> fields = [
  RequiredField(1, 'ID', Type.uint32),
  RequiredField(2, "Name", Type.string),
  OptionalField(3, "Email", Type.string, 'tom@example.com')
];

main() {
  File file = File("example.bin");
  if (file.existsSync()) {
    var bytes = file.readAsBytesSync();
    print(bytes);
    var message = protobuf.decode(ProtoBytes(fields, bytes as Uint8List));
    print(message.toString());
  } else {
    var message = EncoderMessage(fields);
    message[fields[0]] = 1;
    message[fields[1]] = 'Tom';
    var proto = protobuf.encode(message);
    print(proto.bytes);
    file.writeAsBytesSync(proto.bytes);
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  pbconv: ^0.5.9

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:pbconv/pbconv.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
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]
50
Learn more about scoring.

We analyzed this package on Nov 4, 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: Flutter, other

Primary library: package:pbconv/pbconv.dart with components: io.

Health issues and suggestions

Document public APIs. (-0.13 points)

97 out of 100 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/codec.dart.

Run dartfmt to format lib/codec.dart.

Format lib/decoder.dart.

Run dartfmt to format lib/decoder.dart.

Format lib/encoder.dart.

Run dartfmt to format lib/encoder.dart.

Fix additional 3 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/extends.dart (Run dartfmt to format lib/extends.dart.)
  • lib/field.dart (Run dartfmt to format lib/field.dart.)
  • lib/message.dart (Run dartfmt to format lib/message.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0