@@ -19,10 +19,11 @@ package fory
1919
2020import (
2121 "fmt"
22- "github.com/stretchr/testify/require"
2322 "reflect"
2423 "testing"
2524 "unsafe"
25+
26+ "github.com/stretchr/testify/require"
2627)
2728
2829func primitiveData () []interface {} {
@@ -221,7 +222,7 @@ func TestSerializeStructSimple(t *testing.T) {
221222 type A struct {
222223 F1 []string
223224 }
224- require .Nil (t , fory .RegisterTagType ( "example.A" , A {} ))
225+ require .Nil (t , fory .Register ( A {}, "example.A" ))
225226 serde (t , fory , A {})
226227 serde (t , fory , & A {})
227228 serde (t , fory , A {F1 : []string {"str1" , "" , "str2" }})
@@ -231,7 +232,7 @@ func TestSerializeStructSimple(t *testing.T) {
231232 F1 []string
232233 F2 map [string ]int32
233234 }
234- require .Nil (t , fory .RegisterTagType ( "example.B" , B {} ))
235+ require .Nil (t , fory .Register ( B {}, "example.B" ))
235236 serde (t , fory , B {})
236237 serde (t , fory , B {
237238 F1 : []string {"str1" , "" , "str2" },
@@ -291,7 +292,7 @@ func newFoo() Foo {
291292func TestSerializeStruct (t * testing.T ) {
292293 for _ , referenceTracking := range []bool {false , true } {
293294 fory := NewFory (referenceTracking )
294- require .Nil (t , fory .RegisterTagType ( "example.Bar" , Bar {} ))
295+ require .Nil (t , fory .Register ( Bar {}, "example.Bar" ))
295296 serde (t , fory , & Bar {})
296297 bar := Bar {F1 : 1 , F2 : "str" }
297298 serde (t , fory , bar )
@@ -301,13 +302,13 @@ func TestSerializeStruct(t *testing.T) {
301302 F1 Bar
302303 F2 interface {}
303304 }
304- require .Nil (t , fory .RegisterTagType ( "example.A" , A {} ))
305+ require .Nil (t , fory .Register ( A {}, "example.A" ))
305306 serde (t , fory , A {})
306307 serde (t , fory , & A {})
307308 serde (t , fory , A {F1 : Bar {F1 : 1 , F2 : "str" }, F2 : - 1 })
308309 serde (t , fory , & A {F1 : Bar {F1 : 1 , F2 : "str" }, F2 : - 1 })
309310
310- require .Nil (t , fory .RegisterTagType ( "example.Foo" , Foo {} ))
311+ require .Nil (t , fory .Register ( Foo {}, "example.Foo" ))
311312 foo := newFoo ()
312313 serde (t , fory , foo )
313314 serde (t , fory , & foo )
@@ -320,7 +321,7 @@ func TestSerializeCircularReference(t *testing.T) {
320321 type A struct {
321322 A1 * A
322323 }
323- require .Nil (t , fory .RegisterTagType ( "example.A" , A {} ))
324+ require .Nil (t , fory .Register ( A {}, "example.A" ))
324325 // If use `A{}` instead of `&A{}` and pass `a` instead of `&a`, there will be serialization data duplication
325326 // and can't be deserialized by other languages too.
326327 // TODO(chaokunyang) If pass by value(have a copy) and there are some inner value reference, return a readable
@@ -340,7 +341,7 @@ func TestSerializeCircularReference(t *testing.T) {
340341 F2 * B
341342 F3 * B
342343 }
343- require .Nil (t , fory .RegisterTagType ( "example.B" , B {} ))
344+ require .Nil (t , fory .Register ( B {}, "example.B" ))
344345 b := & B {F1 : "str" }
345346 b .F2 = b
346347 b .F3 = b
@@ -368,8 +369,8 @@ func TestSerializeComplexReference(t *testing.T) {
368369 F3 * A
369370 F4 * B
370371 }
371- require .Nil (t , fory .RegisterTagType ( "example.A" , A {} ))
372- require .Nil (t , fory .RegisterTagType ( "example.B" , B {} ))
372+ require .Nil (t , fory .Register ( A {}, "example.A" ))
373+ require .Nil (t , fory .Register ( B {}, "example.B" ))
373374
374375 a := & A {F1 : "str" }
375376 a .F2 = a
@@ -484,8 +485,8 @@ func serde(t *testing.T, fory *Fory, value interface{}) {
484485
485486func BenchmarkMarshal (b * testing.B ) {
486487 fory := NewFory (true )
487- require .Nil (b , fory .RegisterTagType ( "example.Foo" , Foo {} ))
488- require .Nil (b , fory .RegisterTagType ( "example.Bar" , Bar {} ))
488+ require .Nil (b , fory .Register ( Foo {}, "example.Foo" ))
489+ require .Nil (b , fory .Register ( Bar {}, "example.Bar" ))
489490 value := benchData ()
490491 for i := 0 ; i < b .N ; i ++ {
491492 _ , err := fory .Marshal (value )
@@ -497,8 +498,8 @@ func BenchmarkMarshal(b *testing.B) {
497498
498499func BenchmarkUnmarshal (b * testing.B ) {
499500 fory := NewFory (true )
500- require .Nil (b , fory .RegisterTagType ( "example.Foo" , Foo {} ))
501- require .Nil (b , fory .RegisterTagType ( "example.Bar" , Bar {} ))
501+ require .Nil (b , fory .Register ( Foo {}, "example.Foo" ))
502+ require .Nil (b , fory .Register ( Bar {}, "example.Bar" ))
502503 value := benchData ()
503504 data , err := fory .Marshal (value )
504505 if err != nil {
@@ -610,10 +611,10 @@ func TestStructWithNestedSlice(t *testing.T) {
610611 }
611612
612613 fory := NewFory (true )
613- if err := fory .RegisterTagType ( " Example" , Example {} ); err != nil {
614+ if err := fory .Register ( Example {}, " Example" ); err != nil {
614615 panic (err )
615616 }
616- if err := fory .RegisterTagType ( " Item" , Item {} ); err != nil {
617+ if err := fory .Register ( Item {}, " Item" ); err != nil {
617618 panic (err )
618619 }
619620
0 commit comments