registerGroup method
Registers a group of related types under a single extId.
Each type in the group gets a unique subId (integer). The subId is
automatically prepended to the encoded payload.
Benefits:
- ID conservation: Uses only one extension ID for multiple types.
- Performance: Grouped types use the same high-performance routing logic as standalone extensions.
Example:
mp.registerGroup(
extId: 2,
builder: (g) {
g.add<Circle>(
subId: 1,
encoder: (c, p) => p.packDouble(c.radius),
decoder: (u, l) => Circle(u.unpackDouble()!),
);
g.add<Rectangle>(
subId: 2,
encoder: (r, p) => p.packAll([r.w, r.h]),
decoder: (u, l) {
final w = u.unpackDouble()!;
final h = u.unpackDouble()!;
return Rectangle(w, h);
},
);
},
);
Implementation
void registerGroup({
required int extId,
required void Function(MessagePackGroup group) builder,
}) => _registry.registerGroup(extId: extId, builder: builder);