Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to encode to-and-from abstract objects #18

Open
Stebalien opened this issue Jul 7, 2017 · 1 comment
Open

Add a way to encode to-and-from abstract objects #18

Stebalien opened this issue Jul 7, 2017 · 1 comment

Comments

@Stebalien
Copy link
Member

Stebalien commented Jul 7, 2017

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.

@Stebalien
Copy link
Member Author

Related: https://github.com/polydawn/refmt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant