Documentation ¶
Index ¶
Constants ¶
const ( Raw = 0x55 DagProtobuf = 0x70 DagCBOR = 0x71 Libp2pKey = 0x72 GitRaw = 0x78 EthBlock = 0x90 EthBlockList = 0x91 EthTxTrie = 0x92 EthTx = 0x93 EthTxReceiptTrie = 0x94 EthTxReceipt = 0x95 EthStateTrie = 0x96 EthAccountSnapshot = 0x97 EthStorageTrie = 0x98 BitcoinBlock = 0xb0 BitcoinTx = 0xb1 ZcashBlock = 0xc0 ZcashTx = 0xc1 DecredBlock = 0xe0 DecredTx = 0xe1 )
These are multicodec-packed content types. The should match the codes described in the authoritative document: https://github.com/multiformats/multicodec/blob/master/table.csv
const EmptyCidStr = CidStr("")
EmptyCidStr is a constant for a zero/uninitialized/sentinelvalue cid; it is declared mainly for readability in checks for sentinel values.
Variables ¶
var ( // ErrVarintBuffSmall means that a buffer passed to the cid parser was not // long enough, or did not contain an invalid cid ErrVarintBuffSmall = errors.New("reading varint: buffer too small") // ErrVarintTooBig means that the varint in the given cid was above the // limit of 2^64 ErrVarintTooBig = errors.New("reading varint: varint bigger than 64bits" + " and not supported") // ErrCidTooShort means that the cid passed to decode was not long // enough to be a valid Cid ErrCidTooShort = errors.New("cid too short") // ErrInvalidEncoding means that selected encoding is not supported // by this Cid version ErrInvalidEncoding = errors.New("invalid base encoding") )
var CodecToStr = map[uint64]string{ Raw: "raw", DagProtobuf: "protobuf", DagCBOR: "cbor", Libp2pKey: "libp2p-key", GitRaw: "git-raw", EthBlock: "eth-block", EthBlockList: "eth-block-list", EthTxTrie: "eth-tx-trie", EthTx: "eth-tx", EthTxReceiptTrie: "eth-tx-receipt-trie", EthTxReceipt: "eth-tx-receipt", EthStateTrie: "eth-state-trie", EthAccountSnapshot: "eth-account-snapshot", EthStorageTrie: "eth-storage-trie", BitcoinBlock: "bitcoin-block", BitcoinTx: "bitcoin-tx", ZcashBlock: "zcash-block", ZcashTx: "zcash-tx", DecredBlock: "decred-block", DecredTx: "decred-tx", }
CodecToStr maps the numeric codec to its name
var Codecs = map[string]uint64{ "v0": DagProtobuf, "raw": Raw, "protobuf": DagProtobuf, "cbor": DagCBOR, "libp2p-key": Libp2pKey, "git-raw": GitRaw, "eth-block": EthBlock, "eth-block-list": EthBlockList, "eth-tx-trie": EthTxTrie, "eth-tx": EthTx, "eth-tx-receipt-trie": EthTxReceiptTrie, "eth-tx-receipt": EthTxReceipt, "eth-state-trie": EthStateTrie, "eth-account-snapshot": EthAccountSnapshot, "eth-storage-trie": EthStorageTrie, "bitcoin-block": BitcoinBlock, "bitcoin-tx": BitcoinTx, "zcash-block": ZcashBlock, "zcash-tx": ZcashTx, "decred-block": DecredBlock, "decred-tx": DecredTx, }
Codecs maps the name of a codec to its type
var EmptyCidStruct = CidStruct{}
EmptyCidStruct is a constant for a zero/uninitialized/sentinelvalue cid; it is declared mainly for readability in checks for sentinel values.
Note: it's not actually a const; the compiler does not allow const structs.
Functions ¶
This section is empty.
Types ¶
type Cid ¶
type Cid interface { Version() uint64 // Yields the version prefix as a uint. Multicodec() uint64 // Yields the multicodec as a uint. Multihash() mh.Multihash // Yields the multihash segment. String() string // Produces the CID formatted as b58 string. Bytes() []byte // Produces the CID formatted as raw binary. Prefix() Prefix // Produces a tuple of non-content metadata. }
Cid represents a self-describing content adressed identifier.
A CID is composed of:
- a Version of the CID itself,
- a Multicodec (indicates the encoding of the referenced content),
- and a Multihash (which identifies the referenced content).
(Note that the Multihash further contains its own version and hash type indicators.)
type CidStr ¶
type CidStr string
CidStr is a representation of a Cid as a string type containing binary.
Using golang's string type is preferable over byte slices even for binary data because golang strings are immutable, usable as map keys, trivially comparable with built-in equals operators, etc.
Please do not cast strings or bytes into the CidStr type directly; use a parse method which validates the data and yields a CidStr.
func CidStrParse ¶
CidStrParse takes a binary byte slice, parses it, and returns either a valid CidStr, or the zero CidStr and an error.
For CidV1, the data buffer is in the form:
<version><codec-type><multihash>
CidV0 are also supported. In particular, data buffers starting with length 34 bytes, which starts with bytes [18,32...] are considered binary multihashes.
The multicodec bytes are not parsed to verify they're a valid varint; no further reification is performed.
Multibase encoding should already have been unwrapped before parsing; if you have a multibase-enveloped string, use CidStrDecode instead.
CidStrParse is the inverse of Cid.Bytes().
func (CidStr) Bytes ¶
Bytes produces a raw binary format of the CID.
(For CidStr, this method is only distinct from casting because of compatibility with v0 CIDs.)
func (CidStr) Multicodec ¶
type CidStruct ¶
type CidStruct struct {
// contains filtered or unexported fields
}
CidStruct represents a CID in a struct format.
This format complies with the exact same Cid interface as the CidStr implementation, but completely pre-parses the Cid metadata. CidStruct is a tad quicker in case of repeatedly accessed fields, but requires more reshuffling to parse and to serialize. CidStruct is not usable as a map key, because it contains a Multihash reference, which is a slice, and thus not "comparable" as a primitive.
Beware of zero-valued CidStruct: it is difficult to distinguish an incorrectly-initialized "invalid" CidStruct from one representing a v0 cid.
func CidStructParse ¶
CidStructParse takes a binary byte slice, parses it, and returns either a valid CidStruct, or the zero CidStruct and an error.
For CidV1, the data buffer is in the form:
<version><codec-type><multihash>
CidV0 are also supported. In particular, data buffers starting with length 34 bytes, which starts with bytes [18,32...] are considered binary multihashes.
The multicodec bytes are not parsed to verify they're a valid varint; no further reification is performed.
Multibase encoding should already have been unwrapped before parsing; if you have a multibase-enveloped string, use CidStructDecode instead.
CidStructParse is the inverse of Cid.Bytes().
func (CidStruct) Multicodec ¶
type Prefix ¶
Prefix represents all the metadata of a Cid, that is, the Version, the Codec, the Multihash type and the Multihash length. It does not contains any actual content information. NOTE: The use -1 in MhLength to mean default length is deprecated,
use the V0Builder or V1Builder structures instead