ipfs / go-ipld-format

IPLD Node and Resolver interfaces in Go
https://github.com/ipld/ipld
MIT License
64 stars 26 forks source link

It's unclear what types `Resolve(...)` can return. #25

Open Stebalien opened 7 years ago

Stebalien commented 7 years ago

For example, let's say that I'm expecting a number. Should I try casting to a uint64?, float?, etc. We should either provide "canonical" types aliases:

type Integer uint64
type String string
// ...

Or return a custom type:

type Value interface{}

func (v Value) Int() uint64, error {}
func (v Value) String() string, error {}
func (v Value) Nil() error {}
whyrusleeping commented 7 years ago

We can't know what it returns though. It can return literally anything.

Stebalien commented 7 years ago

It can't, e.g., return a peer.ID, can it? That is, I assume it can only return primitives. The problem is that it's unclear what primitives it can return. See the example in the issue body; CBOR, e.g., encodes integers as varints but nothing indicates if go-ipld-cbor can return int, int32, int64, BigInt, float32, or all of the above.

Basically, we need consistent set of primitive types.

whyrusleeping commented 7 years ago

No, it could totally return a peer.ID, or a ProtoNode, or an ethereum transaction, or anything else really

On Fri, Sep 1, 2017, 5:28 PM Steven Allen notifications@github.com wrote:

It can't, e.g., return a peer.ID, can it? That is, I assume it can only return primitives. The problem is that it's unclear what primitives it can return. See the example in the issue body; CBOR, e.g., encodes integers as varints but nothing indicates if go-ipld-cbor can return int, int32, int64, BigInt, float32, or all of the above.

Basically, we need consistent set of primitive types.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ipfs/go-ipld-format/issues/25#issuecomment-326709509, or mute the thread https://github.com/notifications/unsubscribe-auth/ABL4HIVn6qh0jL4rhCb-u6g9-7bsM9OSks5seKEVgaJpZM4O68HN .

Kubuxu commented 7 years ago

CBOR also can encode either floating point or normal integers.