missing unmarshalling of content bytes before encoding and generation… #86
@ -7,6 +7,7 @@ package utils
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
canonicalJson "github.com/gibson042/canonicaljson-go"
|
canonicalJson "github.com/gibson042/canonicaljson-go"
|
||||||
"github.com/ipfs/go-cid"
|
"github.com/ipfs/go-cid"
|
||||||
cbor "github.com/ipfs/go-ipld-cbor"
|
cbor "github.com/ipfs/go-ipld-cbor"
|
||||||
@ -66,10 +67,9 @@ func GetAttributeAsString(obj map[string]interface{}, attr string) (string, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CIDFromJSONBytesUsingIpldPrime returns CID (dagcbor) for json (as bytes).
|
// CIDFromJSONBytesUsingIpldPrime returns CID (dagcbor) for json (as bytes).
|
||||||
func CIDFromJSONBytesUsingIpldPrime(content []byte) (string, error) {
|
|
||||||
|
|
||||||
// This is combination of samples for unmarshalling and linking
|
// This is combination of samples for unmarshalling and linking
|
||||||
// see: https://pkg.go.dev/github.com/ipld/go-ipld-prime
|
// see: https://pkg.go.dev/github.com/ipld/go-ipld-prime
|
||||||
|
func CIDFromJSONBytesUsingIpldPrime(content []byte) (string, error) {
|
||||||
np := basicnode.Prototype.Any // Pick a stle for the in-memory data.
|
np := basicnode.Prototype.Any // Pick a stle for the in-memory data.
|
||||||
nb := np.NewBuilder() // Create a builder.
|
nb := np.NewBuilder() // Create a builder.
|
||||||
err := dagjson.Decode(nb, bytes.NewReader(content)) // Hand the builder to decoding -- decoding will fill it in!
|
err := dagjson.Decode(nb, bytes.NewReader(content)) // Hand the builder to decoding -- decoding will fill it in!
|
||||||
|
Loading…
Reference in New Issue
Block a user