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
ld
go-ld-prime
Commits
fc47eb2f
Commit
fc47eb2f
authored
Jul 15, 2021
by
Rod Vagg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify refmt usage
parent
79994066
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
8 additions
and
14 deletions
+8
-14
adl/rot13adl/example_test.go
adl/rot13adl/example_test.go
+3
-4
codec/dagjson/multicodec.go
codec/dagjson/multicodec.go
+1
-4
node/bindnode/example_test.go
node/bindnode/example_test.go
+2
-3
node/tests/testcase.go
node/tests/testcase.go
+1
-1
schema/schema2/typesystem_test.go
schema/schema2/typesystem_test.go
+1
-2
No files found.
adl/rot13adl/example_test.go
View file @
fc47eb2f
...
...
@@ -7,7 +7,6 @@ import (
"strings"
"github.com/ipfs/go-cid"
"github.com/polydawn/refmt/json"
"github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/adl/rot13adl"
...
...
@@ -25,7 +24,7 @@ func ExampleUnmarshallingToADL() {
nb
:=
rot13adl
.
Prototype
.
SubstrateRoot
.
NewBuilder
()
// Unmarshal -- using the substrate's nodebuilder just like you'd unmarshal with any other nodebuilder.
err
:=
dagjson
.
Unmarshal
(
nb
,
json
.
New
Decode
r
(
strings
.
NewReader
(
`"n pbby fgevat"`
))
,
true
)
err
:=
dagjson
.
Decode
(
nb
,
strings
.
NewReader
(
`"n pbby fgevat"`
))
fmt
.
Printf
(
"unmarshal error: %v
\n
"
,
err
)
// Use `Reify` to get the synthetic high-level view of the ADL data.
...
...
@@ -52,7 +51,7 @@ func ExampleLoadingToADL() {
nb
:=
rot13adl
.
Prototype
.
SubstrateRoot
.
NewBuilder
()
// Unmarshal -- using the substrate's nodebuilder just like you'd unmarshal with any other nodebuilder.
err
:=
dagjson
.
Unmarshal
(
nb
,
json
.
New
Decode
r
(
strings
.
NewReader
(
`"n pbby fgevat"`
))
,
true
)
err
:=
dagjson
.
Decode
(
nb
,
strings
.
NewReader
(
`"n pbby fgevat"`
))
fmt
.
Printf
(
"unmarshal error: %v
\n
"
,
err
)
substrateNode
:=
nb
.
Build
()
...
...
@@ -108,7 +107,7 @@ func ExampleCreatingViaADL() {
// To marshal the ADL, just use marshal methods on its substrate as normal:
var
marshalBuffer
bytes
.
Buffer
err
:=
dagjson
.
Marshal
(
substrateNode
,
json
.
NewEncoder
(
&
marshalBuffer
,
json
.
EncodeOptions
{}),
true
)
err
:=
dagjson
.
Encode
(
substrateNode
,
&
marshalBuffer
)
fmt
.
Printf
(
"marshalled: %v
\n
"
,
marshalBuffer
.
String
())
fmt
.
Printf
(
"marshal error: %v
\n
"
,
err
)
...
...
codec/dagjson/multicodec.go
View file @
fc47eb2f
...
...
@@ -53,8 +53,5 @@ func Encode(n ipld.Node, w io.Writer) error {
// Shell out directly to generic inspection path.
// (There's not really any fastpaths of note for json.)
// Write another function if you need to tune encoding options about whitespace.
return
Marshal
(
n
,
json
.
NewEncoder
(
w
,
json
.
EncodeOptions
{
Line
:
nil
,
Indent
:
nil
,
}),
true
)
return
Marshal
(
n
,
json
.
NewEncoder
(
w
,
json
.
EncodeOptions
{}),
true
)
}
node/bindnode/example_test.go
View file @
fc47eb2f
...
...
@@ -8,7 +8,6 @@ import (
"github.com/ipld/go-ipld-prime/fluent/qp"
"github.com/ipld/go-ipld-prime/node/bindnode"
"github.com/ipld/go-ipld-prime/schema"
refmtjson
"github.com/polydawn/refmt/json"
)
func
ExampleWrap_withSchema
()
{
...
...
@@ -40,7 +39,7 @@ func ExampleWrap_withSchema() {
node
:=
bindnode
.
Wrap
(
person
,
schemaType
)
nodeRepr
:=
node
.
Representation
()
dagjson
.
Marshal
(
nodeRepr
,
refmtjson
.
NewEncoder
(
os
.
Stdout
,
refmtjson
.
EncodeOptions
{}),
true
)
dagjson
.
Encode
(
nodeRepr
,
os
.
Stdout
)
// Output:
// {"Name":"Michael","Friends":["Sarah","Alex"]}
...
...
@@ -76,7 +75,7 @@ func ExamplePrototype_onlySchema() {
}
nodeRepr
:=
node
.
(
schema
.
TypedNode
)
.
Representation
()
dagjson
.
Marshal
(
nodeRepr
,
refmtjson
.
NewEncoder
(
os
.
Stdout
,
refmtjson
.
EncodeOptions
{}),
true
)
dagjson
.
Encode
(
nodeRepr
,
os
.
Stdout
)
// Output:
// {"Name":"Michael","Friends":["Sarah","Alex"]}
...
...
node/tests/testcase.go
View file @
fc47eb2f
...
...
@@ -191,7 +191,7 @@ func (tcase testcase) Test(t *testing.T, np, npr ipld.NodePrototype) {
func
testUnmarshal
(
t
*
testing
.
T
,
np
ipld
.
NodePrototype
,
data
string
,
expectFail
error
)
ipld
.
Node
{
t
.
Helper
()
nb
:=
np
.
NewBuilder
()
err
:=
dagjson
.
Unmarshal
(
nb
,
json
.
New
Decode
r
(
strings
.
NewReader
(
data
))
,
true
)
err
:=
dagjson
.
Decode
(
nb
,
strings
.
NewReader
(
data
))
switch
{
case
expectFail
==
nil
&&
err
!=
nil
:
t
.
Fatalf
(
"fixture parse failed: %s"
,
err
)
...
...
schema/schema2/typesystem_test.go
View file @
fc47eb2f
...
...
@@ -5,7 +5,6 @@ import (
"strings"
"testing"
"github.com/polydawn/refmt/json"
.
"github.com/warpfork/go-wish"
"github.com/ipld/go-ipld-prime/codec/dagjson"
...
...
@@ -206,7 +205,7 @@ func testParse(t *testing.T, schemajson string, expectParseErr error, expectType
func
parseSchema
(
schemajson
string
)
(
schemadmt
.
Schema
,
error
)
{
nb
:=
schemadmt
.
Type
.
Schema__Repr
.
NewBuilder
()
if
err
:=
dagjson
.
Unmarshal
(
nb
,
json
.
New
Decode
r
(
strings
.
NewReader
(
schemajson
))
,
true
)
;
err
!=
nil
{
if
err
:=
dagjson
.
Decode
(
nb
,
strings
.
NewReader
(
schemajson
));
err
!=
nil
{
return
nil
,
err
}
return
nb
.
Build
()
.
(
schemadmt
.
Schema
),
nil
...
...
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