Skip to main content
Search Documentation & Spec
Type to search all 17 pages

OmniBuf
for Dart.

Pure Dart 3 library on pub.dev built on Uint8List and ByteData. Define declarative class schemas, bridge package:protobuf messages, or generate typed classes and lazy Opaque views for AOT Flutter and server runtimes.

Add pub.dev Package
$ dart pub add omnibuf

Three ways to use OmniBuf in Dart.

All three share the exact same v1 DRAFT-1 binary layout across Flutter, Dart VM, and web.

Declarative OmniBufSchema codecs

Bind plain Dart classes directly with OmniBufSchema field getters and setters. Zero reflection, zero codegen, and full replace or merge decoding semantics.

OmniBufSchema Class
import 'package:omnibuf/omnibuf.dart';

class SensorSample {
  String sensorId;
  double celsius;
  int seq;
  SensorSample({this.sensorId = '', this.celsius = 0.0, this.seq = 0});
}

final sensorSchema = OmniBufSchema<SensorSample>(
  typeName: 'SensorSample',
  create: SensorSample.new,
  fields: [
    OmniBufSchemaField.string(1, 'sensor_id', (m) => m.sensorId, (m, v) => m.sensorId = v),
    OmniBufSchemaField.float64(2, 'celsius', (m) => m.celsius, (m, v) => m.celsius = v),
    OmniBufSchemaField.uint64(3, 'seq', (m) => m.seq, (m, v) => m.seq = v),
  ],
);

final pkt = sensorSchema.encode(SensorSample(sensorId: 'rack-42', celsius: 21.75, seq: 1042));
final decoded = sensorSchema.decode(pkt);
Dart 3 type mapping
Dart type
Protobuf type
int (uint32 / uint64)
uint32 / uint64
int (sint32 / sint64)
sint32 / sint64
bool
bool
double (float32 / float64)
float / double
String
string
Uint8List
bytes
Enum
enum
Class (OmniBufSchema<T>)
message
List<T>
repeated T
Map<K, V>
map<K, V>

Dart has a single 64-bit int and 64-bit double type, so OmniBufSchemaField factories (uint32, uint64, sint32, sint64, fixed32, sfixed32, fixed64, sfixed64, float32, float64) pick the exact wire encoding for each field.

Standard package:protobuf messages

Apps already using package:protobuf pass any GeneratedMessage into ProtobufOmniBufCodec.encode and decode via BuilderInfo.

package:protobuf Bridge
import 'package:omnibuf/omnibuf.dart';

final pkt = ProtobufOmniBufCodec.encode(protoPeer);
final copy = ProtobufOmniBufCodec.decode(pkt, PeerUpdate.create);

Generated classes with protoc-gen-omnibuf-dart

protoc-gen-omnibuf-dart emits idiomatic Dart 3 message classes, single-pass Uint8List encoders, and lazy Opaque* views. Nested field reads finish in ~393 ns and single-field splices in ~759 ns.

buf.gen.yaml
version: v2
clean: true
plugins:
  - local: protoc-gen-omnibuf-dart
    out: lib/src/generated
Lint & Generate with Buf
$ buf lint
$ buf generate
Generated Message & Opaque Splice
import 'package:omnibuf/omnibuf.dart';
import 'package:my_app/src/generated/omnibuf/bench/peer.omnibuf.dart';

final pkt = peer.encode();

final view = OpaquePeerUpdate(pkt);
final city = view.locationOpaque?.city;

view.sequence = view.sequence + 1;
final updated = view.marshalAppend();

gRPC &amp; Connect in Dart.

Detached library entrypoints package:omnibuf/grpc.dart and package:omnibuf/connect.dart plug into package:grpc and Connect-Dart without adding RPC dependencies to core package:omnibuf/omnibuf.dart.

Codec names: "omnibuf" (compact) · "x-omnibuf" (with Field #0)

omnibuf/grpc.dart & omnibuf/connect.dart
// package:grpc (separate entrypoint: package:omnibuf/grpc.dart)
import 'package:grpc/grpc.dart';
import 'package:omnibuf/grpc.dart';

final reqCodec = OmniBufGrpcCodec<PingReq>(decode: PingReq.fromOmniBufBytes);
final respCodec = OmniBufGrpcCodec<PingResp>(decode: PingResp.fromOmniBufBytes);
final method = ClientMethod<PingReq, PingResp>(
  '/acme.v1.Svc/Ping',
  reqCodec.serialize,
  respCodec.deserialize,
);

// Connect-Dart (separate entrypoint: package:omnibuf/connect.dart)
import 'package:omnibuf/connect.dart';
final connectCodec = OmniBufConnectCodec<PingReq>(decode: PingReq.fromOmniBufBytes);

Dart questions.

Does omnibuf work in Flutter apps as well as server-side Dart?

Yes. The runtime uses pure Dart 3 Uint8List and ByteData buffers with no dart:mirrors or native FFI requirements, so it compiles cleanly under Flutter AOT (iOS, Android, desktop), Dart VM, and Dart web targets.

How does ProtobufOmniBufCodec bridge package:protobuf messages?

ProtobufOmniBufCodec walks each generated message's BuilderInfo metadata directly, encoding and decoding standard GeneratedMessage subclasses onto OmniBuf wire bytes with no extra plugin step.

How does decodeBlind inspect packets without a schema?

decodeBlind(pkt) and decodeBlindJson(pkt) decode arbitrary OmniBuf packets directly from their 4-bit wire types. Keys default to field_1, field_2, ... or resolve to Field #0 names when encoded with selfDescribing: true.

Example
import 'package:omnibuf/omnibuf.dart';

final pkt = sensorSchema.encode(sample, selfDescribing: true);
final json = decodeBlindJson(pkt);

Language implementations.

v1 DRAFT-1 · GitHub Feedback →
Architecture, Tooling & Wire Specification