-
Notifications
You must be signed in to change notification settings - Fork 25
Description
I've brought this up in other channels but want to record it here for consideration.
The new interface would look like
type CBORMarshaler interface {
MarshalCBOR() ([]byte, error)
}
type CBORUnmarshaler interface {
UnmarshalCBOR([]byte) error
}
A byte slice oriented marshaling interface has good and bad tradeoffs related to the reader/writer design. Among the bad I see memory efficiency and the difficulty in changing the current interface used across several dependent packages.
The strongest reason for changing the interface and the reason I suggest this change is for interoperability with the go ecosystem. If you take a tour through the golang stdlib encoding package tree a pattern emerges: all Marshal interfaces operate on byte slices with roughly the above function signatures
Marshalers:
The pretty cool golang cbor library we're using in go-filecoin reasonably decided to look for custom marshaler functions with the signatures written above. Given the pattern set by the standard library I think that this library made the best choice, and I imagine other external code will also make the same assumption that the above interface is the best guess at a canonical cbor marshaling interface.
It would be awesome if cbg decided to switch to the same pattern. At the very least it would unlock awesome default interop between all of cbg's consumer package data types and go-filecoin. Thinking further out it would make cbg a friendlier package to the broader go ecosystem.