Skip to content

Commit

Permalink
Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gammazero committed Jan 10, 2024
1 parent 31701f6 commit ada4f2c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ingest/schema/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ func UnwrapAdvertisement(node ipld.Node) (*Advertisement, error) {
return ad, nil
}

// Return the Advertisement's previous CID, or cid.Undef if there is no
// previous CID.
func (a Advertisement) PreviousCid() cid.Cid {
if a.PreviousID == nil {
return cid.Undef
Expand All @@ -110,6 +112,9 @@ func (a Advertisement) Validate() error {
return nil
}

// BytesToAdvertisement deserializes an Advertisement from a buffer. It does
// not check that the given CID matches the data, as this should have been done
// when the data was acquired.
func BytesToAdvertisement(adCid cid.Cid, data []byte) (Advertisement, error) {
adNode, err := decodeIPLDNode(adCid.Prefix().Codec, bytes.NewBuffer(data), AdvertisementPrototype)
if err != nil {
Expand All @@ -122,7 +127,10 @@ func BytesToAdvertisement(adCid cid.Cid, data []byte) (Advertisement, error) {
return *ad, nil
}

func BytesToEntry(entCid cid.Cid, data []byte) (EntryChunk, error) {
// BytesToEntryChunk deserializes an EntryChunk from a buffer. It does not
// check that the given CID matches the data, as this should have been done
// when the data was acquired.
func BytesToEntryChunk(entCid cid.Cid, data []byte) (EntryChunk, error) {
entNode, err := decodeIPLDNode(entCid.Prefix().Codec, bytes.NewBuffer(data), EntryChunkPrototype)
if err != nil {
return EntryChunk{}, err
Expand Down

0 comments on commit ada4f2c

Please sign in to comment.