protobuf
6.1.0, released 2 months ago by google.dev
Provides runtime support for Dart protocol buffer messages generated by protoc_plugin.
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.
- json_serializable
Automatically generate code for converting Dart classes to and from JSON.
94Compare - mason
Dart template generator for quick file creation
89Compare - code_assets
Provides the hook protocol specification for bundling native code with Dart packages.
88Compare - copy_with_extension_gen
Generate type‑safe copyWith extensions for annotated classes and record typedefs.
85Compare
Works with
Packages commonly used together with protobuf: ones it builds on, ones built on it, and its own family.
- fixnumprotobuf depends on itProvides 32‑ and 64‑bit signed fixed‑width integer types for Dart.
- grpcBuilt on protobufDart implementation of gRPC, a high performance universal RPC framework.
- retrofit_generatorBuilt on protobufGenerates Dio client code from Retrofit‑style annotations.
- protoc_pluginBuilt on protobufGenerates Dart source files from Protocol Buffer (.proto) definitions using the protoc compiler.
- livekit_clientBuilt on protobufFlutter Client SDK for LiveKit to build real-time video, audio, and data features.
- bazel_workerBuilt on protobufProtocol and utilities to implement or invoke persistent Bazel workers
- dlibphonenumberBuilt on protobufParse, format, validate and extract international phone numbers in pure Dart.
- dartastic_opentelemetryBuilt on protobufOpenTelemetry SDK for Dart and Flutter for distributed tracing, metrics, and context propagation.