Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-ld-cbor
Commits
22f3aab1
Commit
22f3aab1
authored
Jan 31, 2020
by
frrist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
docs: add comments describing methods & interfaces
parent
e38da394
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
0 deletions
+7
-0
store.go
store.go
+7
-0
No files found.
store.go
View file @
22f3aab1
...
@@ -13,16 +13,20 @@ import (
...
@@ -13,16 +13,20 @@ import (
cbg
"github.com/whyrusleeping/cbor-gen"
cbg
"github.com/whyrusleeping/cbor-gen"
)
)
// IpldStore wraps a Blockstore and provides an interface for storing and retrieving CBOR encoded data.
type
IpldStore
interface
{
type
IpldStore
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
)
}
}
// IpldBlockstore defines a subset of the go-ipfs-blockstore Blockstore interface providing methods
// for storing and retrieving block-centered data.
type
IpldBlockstore
interface
{
type
IpldBlockstore
interface
{
Get
(
cid
.
Cid
)
(
block
.
Block
,
error
)
Get
(
cid
.
Cid
)
(
block
.
Block
,
error
)
Put
(
block
.
Block
)
error
Put
(
block
.
Block
)
error
}
}
// BasicIpldStore wraps and IpldBlockstore and implements the IpldStore interface.
type
BasicIpldStore
struct
{
type
BasicIpldStore
struct
{
Blocks
IpldBlockstore
Blocks
IpldBlockstore
Atlas
*
atlas
.
Atlas
Atlas
*
atlas
.
Atlas
...
@@ -30,10 +34,12 @@ type BasicIpldStore struct {
...
@@ -30,10 +34,12 @@ type BasicIpldStore struct {
var
_
IpldStore
=
&
BasicIpldStore
{}
var
_
IpldStore
=
&
BasicIpldStore
{}
// NewCborStore returns an IpldStore implementation backed by the provided IpldBlockstore.
func
NewCborStore
(
bs
IpldBlockstore
)
*
BasicIpldStore
{
func
NewCborStore
(
bs
IpldBlockstore
)
*
BasicIpldStore
{
return
&
BasicIpldStore
{
Blocks
:
bs
}
return
&
BasicIpldStore
{
Blocks
:
bs
}
}
}
// Get reads and unmarshals the content at `c` into `out`.
func
(
s
*
BasicIpldStore
)
Get
(
ctx
context
.
Context
,
c
cid
.
Cid
,
out
interface
{})
error
{
func
(
s
*
BasicIpldStore
)
Get
(
ctx
context
.
Context
,
c
cid
.
Cid
,
out
interface
{})
error
{
blk
,
err
:=
s
.
Blocks
.
Get
(
c
)
blk
,
err
:=
s
.
Blocks
.
Get
(
c
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -59,6 +65,7 @@ type cidProvider interface {
...
@@ -59,6 +65,7 @@ type cidProvider interface {
Cid
()
cid
.
Cid
Cid
()
cid
.
Cid
}
}
// Put marshals and writes content `v` to the backing blockstore returning its CID.
func
(
s
*
BasicIpldStore
)
Put
(
ctx
context
.
Context
,
v
interface
{})
(
cid
.
Cid
,
error
)
{
func
(
s
*
BasicIpldStore
)
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment