Example #1
0
File: main.go Project: catgatp/gol
func main() {
	filename := "dump"
	data := []interface{}{-1, 100, "str1", 7.5, time.Now().UTC(), nil, uint8(2), []int{12, 10, 17}}

	fp, err := os.Create(filename)
	if err != nil {
		panic(err)
	}
	buf := fastbuf.New(nil, 0, fp)
	encodebinary.Encode(buf, data)
	buf.FlushToWriter()
	fp.Close()

	data = data[:0]
	dump, _ := ioutil.ReadFile(filename)
	buf = fastbuf.New(dump, 0, nil)
	decoder := encodebinary.NewDecoder(buf)
	decoder.Decode(&data)

	fmt.Println(data)
}
Example #2
0
File: main.go Project: catgatp/gol
func init() {
	inVar = new(exportedtypes.T1)
	inVar.N1 = 20
	inVar.N2 = "test string"
	inVar.N3 = 1
	inVar.N4 = new(exportedtypes.T2)
	inVar.N4.N1 = 12
	inVar.N4.N2 = "new test string"
	inVar.N4.N3 = 1
	inVar.N4.N4 = []string{0: "str0", 1: "str1", 4: "str4"}
	inVar.N4.N5 = map[int]string{1: "str1", 10: "str10"}
	inVar.N4.N6 = map[int]*exportedtypes.T3{}
	inVar.N4.N6[1] = &exportedtypes.T3{N: 12}
	inVar.N4.N6[2] = &exportedtypes.T3{N: 2}

	buf1 = fastbuf.New(nil, 0, nil)
	buf2 = fastbuf.New(nil, 0, nil)
	decoder = encodebinary.NewDecoder(buf2)
	encodebinary.Encode(buf2, inVar)
	gobEncoder = gob.NewEncoder(buf1)
	gobDecoder = gob.NewDecoder(buf2)
}