MCPcopy Create free account
hub / github.com/apache/fory / ExampleFory_Serialize

Function ExampleFory_Serialize

go/fory/fory_test.go:672–703  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

670}
671
672func 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/*
706The following three tests

Callers

nothing calls this directly

Calls 5

WithXlangFunction · 0.85
WithCompatibleFunction · 0.85
NewFunction · 0.70
SerializeMethod · 0.45
DeserializeMethod · 0.45

Tested by

no test coverage detected