()
| 670 | } |
| 671 | |
| 672 | func ExampleFory_Serialize() { |
| 673 | f := New(WithXlang(true), WithCompatible(false)) |
| 674 | list := []any{true, false, "str", -1.1, 1, make([]int32, 5), make([]float64, 5)} |
| 675 | bytes, err := f.Serialize(list) |
| 676 | if err != nil { |
| 677 | panic(err) |
| 678 | } |
| 679 | // bytes can be data serialized by other languages. |
| 680 | var newValue any |
| 681 | if err = f.Deserialize(bytes, &newValue); err != nil { |
| 682 | panic(err) |
| 683 | } |
| 684 | fmt.Println(newValue) |
| 685 | |
| 686 | dict := map[string]any{ |
| 687 | "k1": "v1", |
| 688 | "k2": list, |
| 689 | "k3": -1, |
| 690 | } |
| 691 | bytes, err = f.Serialize(dict) |
| 692 | if err != nil { |
| 693 | panic(err) |
| 694 | } |
| 695 | // bytes can be data serialized by other languages. |
| 696 | if err = f.Deserialize(bytes, &newValue); err != nil { |
| 697 | panic(err) |
| 698 | } |
| 699 | fmt.Println(newValue) |
| 700 | // Output: |
| 701 | // [true false str -1.1 1 [0 0 0 0 0] [0 0 0 0 0]] |
| 702 | // map[k1:v1 k2:[true false str -1.1 1 [0 0 0 0 0] [0 0 0 0 0]] k3:-1] |
| 703 | } |
| 704 | |
| 705 | /* |
| 706 | The following three tests |
nothing calls this directly
no test coverage detected