Debian Codegraph @

_rsrch/cidiface/cid.go

raw
1 package cid
2
3 import (
4 mh "github.com/multiformats/go-multihash"
5 )
6
7 // Cid represents a self-describing content adressed identifier.
8 //
9 // A CID is composed of:
10 //
11 // - a Version of the CID itself,
12 // - a Multicodec (indicates the encoding of the referenced content),
13 // - and a Multihash (which identifies the referenced content).
14 //
15 // (Note that the Multihash further contains its own version and hash type
16 // indicators.)
17 type Cid interface {
18 // n.b. 'yields' means "without copy", 'produces' means a malloc.
19
20 Version() uint64 // Yields the version prefix as a uint.
21 Multicodec() uint64 // Yields the multicodec as a uint.
22 Multihash() mh.Multihash // Yields the multihash segment.
23
24 String() string // Produces the CID formatted as b58 string.
25 Bytes() []byte // Produces the CID formatted as raw binary.
26
27 Prefix() Prefix // Produces a tuple of non-content metadata.
28
29 // some change notes:
30 // - `KeyString() CidString` is gone because we're natively a map key now, you're welcome.
31 // - `StringOfBase(mbase.Encoding) (string, error)` is skipped, maybe it can come back but maybe it should be a formatter's job.
32 // - `Equals(o Cid) bool` is gone because it's now `==`, you're welcome.
33
34 // TODO: make a multi-return method for {v,mc,mh} decomposition. CidStr will be able to implement this more efficiently than if one makes a series of the individual getter calls.
35 }
36
37 // Prefix represents all the metadata of a Cid,
38 // that is, the Version, the Codec, the Multihash type
39 // and the Multihash length. It does not contains
40 // any actual content information.
41 // NOTE: The use -1 in MhLength to mean default length is deprecated,
42 //
43 // use the V0Builder or V1Builder structures instead
44 type Prefix struct {
45 Version uint64
46 Codec uint64
47 MhType uint64
48 MhLength int
49 }