Skip to content

Commit

Permalink
deprecate DumpObject() in favor of better named Encode()
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMure authored and rvagg committed Oct 1, 2024
1 parent 2e94acd commit dde1d15
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion node.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,13 @@ func (n *Node) MarshalJSON() ([]byte, error) {
}

// DumpObject marshals any object into its CBOR serialized byte representation
// TODO: rename
// Deprecated: use Encode instead.
func DumpObject(obj interface{}) (out []byte, err error) {
return Encode(obj)
}

// Encode marshals any object into its CBOR serialized byte representation
func Encode(obj interface{}) (out []byte, err error) {
return marshaller.Marshal(obj)
}

Expand Down
4 changes: 2 additions & 2 deletions node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ func TestBigIntRoundtrip(t *testing.T) {
World: *big.NewInt(99),
}

bytes, err := DumpObject(&one)
bytes, err := Encode(&one)
if err != nil {
t.Fatal(err)
}
Expand All @@ -616,7 +616,7 @@ func TestBigIntRoundtrip(t *testing.T) {
"world": {Hello: big.NewInt(9), World: *big.NewInt(901), Hi: 3},
}

bytes, err = DumpObject(list)
bytes, err = Encode(list)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ func BenchmarkDecodeBlockParallel(b *testing.B) {
}
}

func BenchmarkDumpObject(b *testing.B) {
func BenchmarkEncode(b *testing.B) {
obj := testStruct()
for i := 0; i < b.N; i++ {
bytes, err := DumpObject(obj)
bytes, err := Encode(obj)
if err != nil {
b.Fatal(err, bytes)
}
Expand Down

0 comments on commit dde1d15

Please sign in to comment.