Skip to content
pubscout

protobuf

6.1.0, released 2 months ago by google.dev

Provides runtime support for Dart protocol buffer messages generated by protoc_plugin.

WASM-ready
$ flutter pub add protobuf
Source repository

What it does

The library implements the protobuf wire format, serialization, and deserialization for Dart. Generated .proto files import this package to work with message classes.

AI-written summary of version 6.1.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to work with Protocol Buffers in a Dart or Flutter project
  • You are using protoc_plugin to generate Dart code from .proto definitions

Skip it when

  • You do not need protobuf support or use another serialization format
  • You require a pure Dart solution without generated code

Strengths

  • Official Google-supported implementation
  • Handles large messages and text format conversion
  • Works across all major platforms

Weaknesses

  • Requires code generation step with protoc_plugin
  • No runtime schema introspection

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
3
import 'package:protobuf/protobuf.dart';

class MyMessage extends GeneratedMessage {
  static final BuilderInfo _i = BuilderInfo('MyMessage')
    ..a<int>(1, 'id', PbFieldType.O3)
    ..aOS(2, 'name');
  @override
  BuilderInfo get info_ => _i;
  // generated getters/setters omitted for brevity
}

void main() {
  var msg = MyMessage()..id = 42..name = 'Alice';
  var bytes = msg.writeToBuffer();
  var decoded = MyMessage()..mergeFromBuffer(bytes);
  print(decoded);
}

Alternatives

Packages that do the same job and could replace protobuf.

Works with

Packages commonly used together with protobuf: ones it builds on, ones built on it, and its own family.