Skip to content

Commit

Permalink
Simplify refmt usage
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Jul 16, 2021
1 parent 7999406 commit fc47eb2
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 14 deletions.
7 changes: 3 additions & 4 deletions adl/rot13adl/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.NewDecoder(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.
Expand All @@ -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.NewDecoder(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()
Expand Down Expand Up @@ -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)

Expand Down
5 changes: 1 addition & 4 deletions codec/dagjson/multicodec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
5 changes: 2 additions & 3 deletions node/bindnode/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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"]}
Expand Down Expand Up @@ -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"]}
Expand Down
2 changes: 1 addition & 1 deletion node/tests/testcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.NewDecoder(strings.NewReader(data)), true)
err := dagjson.Decode(nb, strings.NewReader(data))
switch {
case expectFail == nil && err != nil:
t.Fatalf("fixture parse failed: %s", err)
Expand Down
3 changes: 1 addition & 2 deletions schema/schema2/typesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.NewDecoder(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
Expand Down

0 comments on commit fc47eb2

Please sign in to comment.