Overview
Messages crossing process boundaries must be serialized. GoAkt v4 supports pluggable serializers. The default is ProtoSerializer forproto.Message. CBORSerializer supports arbitrary Go types.
ProtoSerializer (default)
Protobuf messages use the default serializer automatically. No registration needed forproto.Message types.
CBOR for plain Go structs
For plain Go structs, useremote.WithSerializers(new(MyMessage), remote.NewCBORSerializer()) when creating the remote
config. Types are registered automatically in the type registry. Both sender and receiver must register the same types
via WithSerializers; for receive-only types, register them the same way β the type is auto-registered for
deserialization.
How Go types are magically serialized
When you pass a concrete Go type toWithSerializers with CBORSerializer, the type is automatically registered
in a global type registry. There is no separate registration step β no RegisterSerializableTypes or similar.
One line does it all:
-
On config build: When
WithSerializers(new(MyMessage), remote.NewCBORSerializer())is applied, GoAkt detects that the serializer isCBORSerializerand the type is a concrete non-proto struct. It registersMyMessagein a global type registry keyed by the typeβs reflected name. -
On serialize: When a message is sent,
CBORSerializerlooks up the type name in the registry, encodes the value as CBOR, and prepends a self-describing frame (total length, type name length, type name, payload). The receiver can reconstruct the exact Go type from the type name. - On deserialize: When bytes arrive, the frame header is parsed, the type name is extracted, and the registry is consulted to resolve the concrete Go type. A new instance is allocated and the CBOR payload is unmarshaled into it.
WithSerializers. For types you only receive (never send),
register them the same way β the type is auto-registered for deserialization. Proto message types are excluded from
this registry; they use protobufβs own type resolution.
The Serializer interface
Custom serializers must implement:| Method | Purpose |
|---|---|
| Serialize | Encode a message into bytes. The encoding must be self-describing so the receiver can reconstruct the concrete type without out-of-band coordination. |
| Deserialize | Decode bytes back into the original Go value. The dynamic type must match what was passed to Serialize. |
WithSerializers(msgType, serializer) on the remote
config.