Open Stebalien opened 7 years ago
That is, something like:
type Node interface { Unmarshal(v interface{}) error // ... } type BlockEncoderFunc func(prefix cid.Prefix, o interface{}) (Node, error) type BlockEncoder map[uint64]BlockEncoderFunc // ... func Encode(o interface{}, prefix cid.Prefix) (Node, error) { if node, ok := node.(Node); ok && node.Cid().Prefix() == prefix { return node, nil } return DefaultBlockEncoder[prefix.Codec](prefix, o) } // ...
This way, we can call Encode(Decode(some_block), some_prefix) to re-encode a block in a new format.
Encode(Decode(some_block), some_prefix)
Related: https://github.com/polydawn/refmt
That is, something like:
This way, we can call
Encode(Decode(some_block), some_prefix)
to re-encode a block in a new format.