ipfs / ipfs/go-ipld-format

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

Open
#18 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
65
Forks
27
PR merge metrics
No merged PRs in 30d

Description

That is, something like:

```go
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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.