Commit c3f8779b authored by tavit ohanian's avatar tavit ohanian

refactor after forking multiformats

parent e4394047
Pipeline #931 passed with stages
in 31 seconds
module gitlab.dms3.io/dms3/public/go-dms3ld-cbor module gitlab.dms3.io/dms3/go-ld-cbor
require ( require (
github.com/multiformats/go-multihash v0.0.14 github.com/multiformats/go-multihash v0.0.14
...@@ -6,10 +6,10 @@ require ( ...@@ -6,10 +6,10 @@ require (
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa // indirect github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa // indirect
github.com/warpfork/go-wish v0.0.0-20180510122957-5ad1f5abf436 // indirect github.com/warpfork/go-wish v0.0.0-20180510122957-5ad1f5abf436 // indirect
github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158 github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158
gitlab.dms3.io/dms3/public/go-block-format v0.0.1 gitlab.dms3.io/dms3/go-block-format v0.0.3
gitlab.dms3.io/dms3/public/go-cid v0.0.1 gitlab.dms3.io/dms3/go-cid v0.0.3
gitlab.dms3.io/dms3/public/go-dms3-util v0.0.1 gitlab.dms3.io/dms3/go-dms3-util v0.0.2
gitlab.dms3.io/dms3/public/go-dms3ld-format v0.0.1 gitlab.dms3.io/dms3/go-ld-format v0.0.2
) )
go 1.15 go 1.15
...@@ -7,7 +7,6 @@ github.com/ipfs/go-cid v0.0.3 h1:UIAh32wymBpStoe83YCzwVQQ5Oy/H0FdxvUS6DJDzms= ...@@ -7,7 +7,6 @@ github.com/ipfs/go-cid v0.0.3 h1:UIAh32wymBpStoe83YCzwVQQ5Oy/H0FdxvUS6DJDzms=
github.com/ipfs/go-cid v0.0.3/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= github.com/ipfs/go-cid v0.0.3/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM=
github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE= github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE=
github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/libp2p/go-buffer-pool v0.0.2/go.mod h1:MvaB6xw5vOrDl8rYZGLFdKAuk/hRoRZd1Vi32+RXyFM=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ= github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ=
github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16 h1:5W7KhL8HVF3XCFOweFD3BNESdnO8ewyYTFT2R+/b8FQ= github.com/minio/sha256-simd v0.0.0-20190131020904-2d45a736cd16 h1:5W7KhL8HVF3XCFOweFD3BNESdnO8ewyYTFT2R+/b8FQ=
...@@ -46,19 +45,21 @@ github.com/warpfork/go-wish v0.0.0-20180510122957-5ad1f5abf436 h1:qOpVTI+BrstcjT ...@@ -46,19 +45,21 @@ github.com/warpfork/go-wish v0.0.0-20180510122957-5ad1f5abf436 h1:qOpVTI+BrstcjT
github.com/warpfork/go-wish v0.0.0-20180510122957-5ad1f5abf436/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw= github.com/warpfork/go-wish v0.0.0-20180510122957-5ad1f5abf436/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw=
github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158 h1:WXhVOwj2USAXB5oMDwRl3piOux2XMV9TANaYxXHdkoE= github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158 h1:WXhVOwj2USAXB5oMDwRl3piOux2XMV9TANaYxXHdkoE=
github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI= github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI=
gitlab.dms3.io/dms3/public/go-block-format v0.0.1 h1:PQ6+E7zY6kUIHET86uJTQHTTj4Z9ZNfP7w281ZdExgk= gitlab.dms3.io/dms3/go-block-format v0.0.3 h1:3gPZUNu5UavbZxbMNd4NDTLG53O7MbmYSwntQwZGKxI=
gitlab.dms3.io/dms3/public/go-block-format v0.0.1/go.mod h1:xlvtW/OF72rOzLa2RVWXX2Uw18qTAWTQEs/Xp7SCnuY= gitlab.dms3.io/dms3/go-block-format v0.0.3/go.mod h1:IbZAFf3fFJa8YW98gaSg/iO9GKtsgVs6+N8OVHmFw1I=
gitlab.dms3.io/dms3/public/go-cid v0.0.1 h1:qs4dtkDigcLGY/58dIZaFjKLt+orrTcmTBvtqaM3570= gitlab.dms3.io/dms3/go-cid v0.0.3 h1:5qZ1sl1Bi26naLz7Vsc8fjWcJKX8bR6njt3WPCteXac=
gitlab.dms3.io/dms3/public/go-cid v0.0.1/go.mod h1:GQw3gc4CSrFY+aX6M+OBQDlg0p5/eQJoRrayaZzkAOQ= gitlab.dms3.io/dms3/go-cid v0.0.3/go.mod h1:qT/Q1NZD31UnWQ+rwsQgzGrrsQhpq7dYSlXf7ulDgtk=
gitlab.dms3.io/dms3/public/go-dms3-util v0.0.1 h1:Gd+kJl1Rc+ZEUb9CIS1ZctQnF9G1oruNFyxUC//QBUQ= gitlab.dms3.io/dms3/go-dms3-util v0.0.2 h1:xXHeLaht5szd3QPdQp5KcfmXbIyRvRPSdQnMkJPRgPo=
gitlab.dms3.io/dms3/public/go-dms3-util v0.0.1/go.mod h1:ymlwtzTNMq8Ug+gVtPAMxXKCKTXwXJAzXS+SUihfKgo= gitlab.dms3.io/dms3/go-dms3-util v0.0.2/go.mod h1:5hPwxzo5zK4NeHE/anWIQGHcIoG7aTl9/Pp0j2zg0l8=
gitlab.dms3.io/dms3/public/go-dms3ld-format v0.0.1 h1:G2jFwYHYNg1xNyNelCqPHWcP643G1WetNKrM9GzUuOo= gitlab.dms3.io/dms3/go-ld-format v0.0.2 h1:e3t6xZ1/3PCuPd/bVaEabLVCE9OjknSrX7y2NZBO4BE=
gitlab.dms3.io/dms3/public/go-dms3ld-format v0.0.1/go.mod h1:S3ODpdL+sAHW0BHDdmx+wn4wwpuf83dHO3EbyhJEfEU= gitlab.dms3.io/dms3/go-ld-format v0.0.2/go.mod h1:KOn0EFd+iXeugBQUGkqco3tWFucYuLiOJ0xB8oURYCg=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67 h1:ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 h1:1wopBVtVdWnn03fZelqdXTqk7U7zPQCb+T4rbU9ZEoU= golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8 h1:1wopBVtVdWnn03fZelqdXTqk7U7zPQCb+T4rbU9ZEoU=
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
...@@ -66,6 +67,8 @@ golang.org/x/sys v0.0.0-20190219092855-153ac476189d h1:Z0Ahzd7HltpJtjAHHxX8QFP3j ...@@ -66,6 +67,8 @@ golang.org/x/sys v0.0.0-20190219092855-153ac476189d h1:Z0Ahzd7HltpJtjAHHxX8QFP3j
golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190219092855-153ac476189d/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210608053332-aa57babbf139 h1:C+AwYEtBp/VQwoLntUmQ/yx3MS9vmZaKNdw5eOpoQe8=
golang.org/x/sys v0.0.0-20210608053332-aa57babbf139/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
...@@ -9,15 +9,15 @@ import ( ...@@ -9,15 +9,15 @@ import (
"strings" "strings"
mh "github.com/multiformats/go-multihash" mh "github.com/multiformats/go-multihash"
blocks "gitlab.dms3.io/dms3/public/go-block-format" blocks "gitlab.dms3.io/dms3/go-block-format"
cid "gitlab.dms3.io/dms3/public/go-cid" cid "gitlab.dms3.io/dms3/go-cid"
node "gitlab.dms3.io/dms3/public/go-dms3ld-format" node "gitlab.dms3.io/dms3/go-ld-format"
) )
// CBORTagLink is the integer used to represent tags in CBOR. // CBORTagLink is the integer used to represent tags in CBOR.
const CBORTagLink = 42 const CBORTagLink = 42
// Node represents an DMS3LD node. // Node represents an LD node.
type Node struct { type Node struct {
obj interface{} obj interface{}
tree []string tree []string
...@@ -38,18 +38,18 @@ var ( ...@@ -38,18 +38,18 @@ var (
ErrArrayOutOfRange = errors.New("array index out of range") ErrArrayOutOfRange = errors.New("array index out of range")
ErrNoLinks = errors.New("tried to resolve through object that had no links") ErrNoLinks = errors.New("tried to resolve through object that had no links")
ErrEmptyLink = errors.New("link value was empty") ErrEmptyLink = errors.New("link value was empty")
ErrInvalidMultibase = errors.New("invalid multibase on DMS3LD link") ErrInvalidMultibase = errors.New("invalid multibase on LD link")
ErrNonStringLink = errors.New("link should have been a string") ErrNonStringLink = errors.New("link should have been a string")
) )
// DecodeBlock decodes a CBOR encoded Block into an DMS3LD Node. // DecodeBlock decodes a CBOR encoded Block into an LD Node.
// //
// This method *does not* canonicalize and *will* preserve the CID. As a matter // This method *does not* canonicalize and *will* preserve the CID. As a matter
// of fact, it will assume that `block.Cid()` returns the correct CID and will // of fact, it will assume that `block.Cid()` returns the correct CID and will
// make no effort to validate this assumption. // make no effort to validate this assumption.
// //
// In general, you should not be calling this method directly. Instead, you // In general, you should not be calling this method directly. Instead, you
// should be calling the `Decode` method from the `go-dms3ld-format` package. That // should be calling the `Decode` method from the `go-ld-format` package. That
// method will pick the right decoder based on the Block's CID. // method will pick the right decoder based on the Block's CID.
// //
// Note: This function keeps a reference to `block` and assumes that it is // Note: This function keeps a reference to `block` and assumes that it is
...@@ -83,7 +83,7 @@ func newObject(block blocks.Block, m interface{}) (*Node, error) { ...@@ -83,7 +83,7 @@ func newObject(block blocks.Block, m interface{}) (*Node, error) {
var _ node.DecodeBlockFunc = DecodeBlock var _ node.DecodeBlockFunc = DecodeBlock
// Decode decodes a CBOR object into an DMS3LD Node. // Decode decodes a CBOR object into an LD Node.
// //
// If passed a non-canonical CBOR node, this function will canonicalize it. // If passed a non-canonical CBOR node, this function will canonicalize it.
// Therefore, `bytes.Equal(b, Decode(b).RawData())` may not hold. If you already // Therefore, `bytes.Equal(b, Decode(b).RawData())` may not hold. If you already
...@@ -103,7 +103,7 @@ func Decode(b []byte, mhType uint64, mhLen int) (*Node, error) { ...@@ -103,7 +103,7 @@ func Decode(b []byte, mhType uint64, mhLen int) (*Node, error) {
return WrapObject(m, mhType, mhLen) return WrapObject(m, mhType, mhLen)
} }
// DecodeInto decodes a serialized DMS3LD cbor object into the given object. // DecodeInto decodes a serialized LD cbor object into the given object.
func DecodeInto(b []byte, v interface{}) error { func DecodeInto(b []byte, v interface{}) error {
return unmarshaller.Unmarshal(b, v) return unmarshaller.Unmarshal(b, v)
} }
......
...@@ -13,9 +13,9 @@ import ( ...@@ -13,9 +13,9 @@ import (
"testing" "testing"
mh "github.com/multiformats/go-multihash" mh "github.com/multiformats/go-multihash"
blocks "gitlab.dms3.io/dms3/public/go-block-format" blocks "gitlab.dms3.io/dms3/go-block-format"
cid "gitlab.dms3.io/dms3/public/go-cid" cid "gitlab.dms3.io/dms3/go-cid"
u "gitlab.dms3.io/dms3/public/go-dms3-util" u "gitlab.dms3.io/dms3/go-dms3-util"
) )
func init() { func init() {
...@@ -34,7 +34,7 @@ func TestNonObject(t *testing.T) { ...@@ -34,7 +34,7 @@ func TestNonObject(t *testing.T) {
// //
// patterns used to generate known good Cids to test against // patterns used to generate known good Cids to test against
// objx := map[string]interface{}{ // objx := map[string]interface{}{
// "a": "DMS3", // "a": "ld",
// } // }
// //
// ndx, err := WrapObject(objx, mh.SHA2_256, -1) // ndx, err := WrapObject(objx, mh.SHA2_256, -1)
...@@ -49,6 +49,10 @@ func TestNonObject(t *testing.T) { ...@@ -49,6 +49,10 @@ func TestNonObject(t *testing.T) {
// t.Fatal(err) // t.Fatal(err)
// } // }
// fmt.Println(ndx.Cid()) // fmt.Println(ndx.Cid())
// DMS3 => bafyreihowikcorpbjzhfhuifmstj7arukumtnjtvjhvt3jvqlpwz5wjqqe
// dms3 => bafyreiclofd5rbup7v5o5eqr4q2cydzqhf3k3bw4i7cwkg2qq6f43hm4vy
// dms3ns => bafyreidq3tiwk6gxm2nqwssvf76thels3a2oeym36lvghl4zavtcf4a6wm
// ld => bafyreiaitxos4k63dsbsvqsn2wklwoelyei2kekdb3gkkr3wman75bohvi
// //
nd, err := WrapObject("", mh.SHA2_256, -1) nd, err := WrapObject("", mh.SHA2_256, -1)
......
...@@ -3,14 +3,14 @@ package cbornode ...@@ -3,14 +3,14 @@ package cbornode
import ( import (
"math/big" "math/big"
cid "gitlab.dms3.io/dms3/public/go-cid" cid "gitlab.dms3.io/dms3/go-cid"
encoding "gitlab.dms3.io/dms3/public/go-dms3ld-cbor/encoding" encoding "gitlab.dms3.io/dms3/go-ld-cbor/encoding"
"github.com/polydawn/refmt/obj/atlas" "github.com/polydawn/refmt/obj/atlas"
) )
// This atlas describes the CBOR Tag (42) for DMS3LD links, such that refmt can marshal and unmarshal them // This atlas describes the CBOR Tag (42) for LD links, such that refmt can marshal and unmarshal them
var cidAtlasEntry = atlas.BuildEntry(cid.Cid{}). var cidAtlasEntry = atlas.BuildEntry(cid.Cid{}).
UseTag(CBORTagLink). UseTag(CBORTagLink).
Transform(). Transform().
...@@ -35,7 +35,7 @@ var BigIntAtlasEntry = atlas.BuildEntry(big.Int{}).Transform(). ...@@ -35,7 +35,7 @@ var BigIntAtlasEntry = atlas.BuildEntry(big.Int{}).Transform().
})). })).
Complete() Complete()
// CborAtlas is the refmt.Atlas used by the CBOR DMS3LD decoder/encoder. // CborAtlas is the refmt.Atlas used by the CBOR LD decoder/encoder.
var CborAtlas atlas.Atlas var CborAtlas atlas.Atlas
var cborSortingMode = atlas.KeySortMode_RFC7049 var cborSortingMode = atlas.KeySortMode_RFC7049
var atlasEntries = []*atlas.AtlasEntry{cidAtlasEntry} var atlasEntries = []*atlas.AtlasEntry{cidAtlasEntry}
......
...@@ -9,50 +9,50 @@ import ( ...@@ -9,50 +9,50 @@ import (
recbor "github.com/polydawn/refmt/cbor" recbor "github.com/polydawn/refmt/cbor"
atlas "github.com/polydawn/refmt/obj/atlas" atlas "github.com/polydawn/refmt/obj/atlas"
cbg "github.com/whyrusleeping/cbor-gen" cbg "github.com/whyrusleeping/cbor-gen"
block "gitlab.dms3.io/dms3/public/go-block-format" block "gitlab.dms3.io/dms3/go-block-format"
cid "gitlab.dms3.io/dms3/public/go-cid" cid "gitlab.dms3.io/dms3/go-cid"
) )
// Dms3LdStore wraps a Blockstore and provides an interface for storing and retrieving CBOR encoded data. // LdStore wraps a Blockstore and provides an interface for storing and retrieving CBOR encoded data.
type Dms3LdStore interface { type LdStore interface {
Get(ctx context.Context, c cid.Cid, out interface{}) error Get(ctx context.Context, c cid.Cid, out interface{}) error
Put(ctx context.Context, v interface{}) (cid.Cid, error) Put(ctx context.Context, v interface{}) (cid.Cid, error)
} }
// Dms3LdBlockstore defines a subset of the go-dms3-blockstore Blockstore interface providing methods // LdBlockstore defines a subset of the go-dms3-blockstore Blockstore interface providing methods
// for storing and retrieving block-centered data. // for storing and retrieving block-centered data.
type Dms3LdBlockstore interface { type LdBlockstore interface {
Get(cid.Cid) (block.Block, error) Get(cid.Cid) (block.Block, error)
Put(block.Block) error Put(block.Block) error
} }
// Dms3LdBlockstoreViewer is a trait that enables zero-copy access to blocks in // LdBlockstoreViewer is a trait that enables zero-copy access to blocks in
// a blockstore. // a blockstore.
type Dms3LdBlockstoreViewer interface { type LdBlockstoreViewer interface {
// View provides zero-copy access to blocks in a blockstore. The callback // View provides zero-copy access to blocks in a blockstore. The callback
// function will be invoked with the value for the key. The user MUST not // function will be invoked with the value for the key. The user MUST not
// modify the byte array, as it could be memory-mapped. // modify the byte array, as it could be memory-mapped.
View(cid.Cid, func([]byte) error) error View(cid.Cid, func([]byte) error) error
} }
// BasicDms3LdStore wraps and Dms3LdBlockstore and implements the Dms3LdStore interface. // BasicLdStore wraps and LdBlockstore and implements the LdStore interface.
type BasicDms3LdStore struct { type BasicLdStore struct {
Blocks Dms3LdBlockstore Blocks LdBlockstore
Viewer Dms3LdBlockstoreViewer Viewer LdBlockstoreViewer
Atlas *atlas.Atlas Atlas *atlas.Atlas
} }
var _ Dms3LdStore = &BasicDms3LdStore{} var _ LdStore = &BasicLdStore{}
// NewCborStore returns an Dms3LdStore implementation backed by the provided Dms3LdBlockstore. // NewCborStore returns an LdStore implementation backed by the provided LdBlockstore.
func NewCborStore(bs Dms3LdBlockstore) *BasicDms3LdStore { func NewCborStore(bs LdBlockstore) *BasicLdStore {
viewer, _ := bs.(Dms3LdBlockstoreViewer) viewer, _ := bs.(LdBlockstoreViewer)
return &BasicDms3LdStore{Blocks: bs, Viewer: viewer} return &BasicLdStore{Blocks: bs, Viewer: viewer}
} }
// Get reads and unmarshals the content at `c` into `out`. // Get reads and unmarshals the content at `c` into `out`.
func (s *BasicDms3LdStore) Get(ctx context.Context, c cid.Cid, out interface{}) error { func (s *BasicLdStore) Get(ctx context.Context, c cid.Cid, out interface{}) error {
if s.Viewer != nil { if s.Viewer != nil {
// zero-copy path. // zero-copy path.
return s.Viewer.View(c, func(b []byte) error { return s.Viewer.View(c, func(b []byte) error {
...@@ -67,7 +67,7 @@ func (s *BasicDms3LdStore) Get(ctx context.Context, c cid.Cid, out interface{}) ...@@ -67,7 +67,7 @@ func (s *BasicDms3LdStore) Get(ctx context.Context, c cid.Cid, out interface{})
return s.decode(blk.RawData(), out) return s.decode(blk.RawData(), out)
} }
func (s *BasicDms3LdStore) decode(b []byte, out interface{}) error { func (s *BasicLdStore) decode(b []byte, out interface{}) error {
cu, ok := out.(cbg.CBORUnmarshaler) cu, ok := out.(cbg.CBORUnmarshaler)
if ok { if ok {
if err := cu.UnmarshalCBOR(bytes.NewReader(b)); err != nil { if err := cu.UnmarshalCBOR(bytes.NewReader(b)); err != nil {
...@@ -88,7 +88,7 @@ type cidProvider interface { ...@@ -88,7 +88,7 @@ type cidProvider interface {
} }
// Put marshals and writes content `v` to the backing blockstore returning its CID. // Put marshals and writes content `v` to the backing blockstore returning its CID.
func (s *BasicDms3LdStore) Put(ctx context.Context, v interface{}) (cid.Cid, error) { func (s *BasicLdStore) Put(ctx context.Context, v interface{}) (cid.Cid, error) {
mhType := uint64(mh.BLAKE2B_MIN + 31) mhType := uint64(mh.BLAKE2B_MIN + 31)
mhLen := -1 mhLen := -1
codec := uint64(cid.DagCBOR) codec := uint64(cid.DagCBOR)
...@@ -175,7 +175,7 @@ func (se SerializationError) Is(o error) bool { ...@@ -175,7 +175,7 @@ func (se SerializationError) Is(o error) bool {
return ok return ok
} }
func NewMemCborStore() Dms3LdStore { func NewMemCborStore() LdStore {
return NewCborStore(newMockBlocks()) return NewCborStore(newMockBlocks())
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment