Exemple #1
0
func main() {
	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}

	buf := fastbuf.New(nil, 0, nil)

	encoderdecoder.Encode(buf, inVar)
	outVar, e := encoderdecoder.Decode(buf)
	//spew.Dump(outVar)
	if reflect.DeepEqual(inVar, outVar) {
		fmt.Println("ok")
	} else {
		fmt.Println("not ok", e)
	}

}
Exemple #2
0
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)
}
Exemple #3
0
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)
}
Exemple #4
0
// Benchmark
package main

import (
	"bytes"
	"fmt"
	"github.com/Cergoo/gol/fastbuf"
	"testing"
)

var (
	fastBuf  = fastbuf.New(nil, 0, nil)
	bytesBuf bytes.Buffer
	r1, r2   testing.BenchmarkResult
	p        = []byte("qqqqqqqqqqqqqqqqqqqqqqqqqqqqqq")
)

func main() {
	operation_name := "Write"
	r1 = testing.Benchmark(benchmark_fastbuf)
	r2 = testing.Benchmark(benchmark_bytesbuf)
	fmt.Print(operation_name, "\n", "fastbuf:", r1, r1.MemString(), "\n", "bytes.Buffer:", r2, r2.MemString(), "\n")

}

func benchmark_fastbuf(b *testing.B) {
	for n := 0; n < b.N; n++ {
		for i := 0; i < 10; i++ {
			fastBuf.Write(p)
		}
		fastBuf.FlushP()
Exemple #5
0
func main() {
	buf := fastbuf.New(nil, 0, nil)
	primitive.PutInt32(buf, 2)
	primitive.PutInt32(buf, 4)
	fmt.Println(buf.FlushP())
}
Exemple #6
0
func main() {
	b := fastbuf.New(nil, 0, nil)
	b.Write([]byte("12"))
	fmt.Print(b.FlushP())

}
Exemple #7
0
// Benchmark
package main

import (
	"fmt"
	"github.com/Cergoo/gol/encode/binary/primitive"
	"github.com/Cergoo/gol/fastbuf"
	"testing"
)

var (
	buf1 = fastbuf.New(nil, 0, nil)
	buf2 = make([]byte, 0, 64)
)

func main() {
	fmt.Println(primitive.EndianBig())
	operation_name := "Write"
	r1 := testing.Benchmark(benchmark_buf1)
	r2 := testing.Benchmark(benchmark_buf2)
	fmt.Print(operation_name, "\n", "buf1:", r1, r1.MemString(), "\n", "buf2:", r2, r2.MemString(), "\n")

}

func benchmark_buf1(b *testing.B) {
	for n := 0; n < b.N; n++ {
		for i := 1; i < 2000; i++ {
			primitive.PutUint16(buf1, uint16(257))
		}
		buf1.ReadWriteReset()
	}