github.com/niubaoshu/gotiny@v0.0.4-0.20211018120156-10d393f19ad0/example/helloworld.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "reflect" 6 7 "github.com/niubaoshu/gotiny" 8 ) 9 10 func main() { 11 src1, src2 := "hello", []byte(" world!") 12 ret1, ret2 := "", []byte{3, 4, 5} 13 gotiny.Unmarshal(gotiny.Marshal(&src1, &src2), &ret1, &ret2) 14 fmt.Println(ret1 + string(ret2)) // print "hello world!" 15 16 enc := gotiny.NewEncoder(src1, src2) 17 dec := gotiny.NewDecoder(ret1, ret2) 18 19 ret1, ret2 = "", []byte{3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 5, 6, 7, 44, 7, 5, 6, 4, 7} 20 dec.DecodeValue(enc.EncodeValue(reflect.ValueOf(src1), reflect.ValueOf(src2)), 21 reflect.ValueOf(&ret1).Elem(), reflect.ValueOf(&ret2).Elem()) 22 fmt.Println(ret1 + string(ret2)) // print "hello world!" 23 }