Skip to content

Request: change cbg.CBOR(Un)marshaler interface to operate over byte slices #9

@ZenGround0

Description

@ZenGround0

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions