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-format
Commits
8cbcd631
Commit
8cbcd631
authored
Jun 19, 2017
by
Jeromy Johnson
Committed by
GitHub
Jun 19, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6 from Stebalien/block-decoding
Implement a block decoding system
parents
1e5ffb60
f5194f0a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
10 deletions
+51
-10
.gx/lastpubver
.gx/lastpubver
+1
-1
coding.go
coding.go
+40
-0
format.go
format.go
+3
-8
package.json
package.json
+7
-1
No files found.
.gx/lastpubver
View file @
8cbcd631
0.4.
7
: Qm
Rxw1auJDHHwamUiSNf1wNDUCtq7iSnJsuVu1zG4dUa1w
0.4.
8
: Qm
cmUTvep15wj4UGSqDYERTg1U9yQnNzDUGWggWorLdkmt
coding.go
0 → 100644
View file @
8cbcd631
package
format
import
(
"fmt"
blocks
"github.com/ipfs/go-block-format"
)
// DecodeBlock functions decode blocks into nodes.
type
DecodeBlockFunc
func
(
block
blocks
.
Block
)
(
Node
,
error
)
// Map from codec types to decoder functions
type
BlockDecoder
map
[
uint64
]
DecodeBlockFunc
// A default set of block decoders.
//
// You SHOULD populate this map from `init` functions in packages that support
// decoding various IPLD formats. You MUST NOT modify this map once `main` has
// been called.
var
DefaultBlockDecoder
BlockDecoder
=
map
[
uint64
]
DecodeBlockFunc
{}
func
(
b
BlockDecoder
)
Decode
(
block
blocks
.
Block
)
(
Node
,
error
)
{
// Short-circuit by cast if we already have a Node.
if
node
,
ok
:=
block
.
(
Node
);
ok
{
return
node
,
nil
}
ty
:=
block
.
Cid
()
.
Type
()
if
decoder
,
ok
:=
b
[
ty
];
ok
{
return
decoder
(
block
)
}
else
{
// TODO: get the *long* name for this format
return
nil
,
fmt
.
Errorf
(
"unrecognized object type: %d"
,
ty
)
}
}
// Decode the given block using the default block decoder.
func
Decode
(
block
blocks
.
Block
)
(
Node
,
error
)
{
return
DefaultBlockDecoder
.
Decode
(
block
)
}
format.go
View file @
8cbcd631
...
...
@@ -4,6 +4,8 @@ import (
"context"
"fmt"
blocks
"github.com/ipfs/go-block-format"
cid
"github.com/ipfs/go-cid"
)
...
...
@@ -18,14 +20,13 @@ type Resolver interface {
}
type
Node
interface
{
blocks
.
Block
Resolver
// ResolveLink is a helper function that calls resolve and asserts the
// output is a link
ResolveLink
(
path
[]
string
)
(
*
Link
,
[]
string
,
error
)
Cid
()
*
cid
.
Cid
// Copy returns a deep copy of this node
Copy
()
Node
...
...
@@ -37,12 +38,6 @@ type Node interface {
// Size returns the size in bytes of the serialized object
Size
()
(
uint64
,
error
)
// RawData marshals the node and returns the marshaled bytes
RawData
()
[]
byte
String
()
string
Loggable
()
map
[
string
]
interface
{}
}
type
NodeGetter
interface
{
...
...
package.json
View file @
8cbcd631
...
...
@@ -12,6 +12,12 @@
"hash"
:
"QmZe3S3sXMWar3oPmrd8jHV8NoAWfPfLGFD8PsK3YrYpqv"
,
"name"
:
"go-cid"
,
"version"
:
"0.7.13"
},
{
"author"
:
"stebalien"
,
"hash"
:
"QmeK8xFAXx4GBpZG6mizck1XAunVtxP8Tmvir5FMwp5MYb"
,
"name"
:
"go-block-format"
,
"version"
:
"0.1.0"
}
],
"gxVersion"
:
"0.10.0"
,
...
...
@@ -19,6 +25,6 @@
"license"
:
""
,
"name"
:
"go-ipld-format"
,
"releaseCmd"
:
"git commit -a -m
\"
gx publish $VERSION
\"
"
,
"version"
:
"0.4.
7
"
"version"
:
"0.4.
8
"
}
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