Example #1
0
File: main.go Project: dams/Sereal
func process(fname string, b []byte) {

	var i interface{}
	d := sereal.Decoder{}

	err := d.Unmarshal(b, &i)

	if err != nil {
		log.Fatalf("error processing %s: %s", fname, err)
	}

	spew.Dump(i)
}
Example #2
0
func process(fname string, b []byte) {

	var i interface{}
	d := sereal.Decoder{}

	err := d.Unmarshal(b, &i)

	if err != nil {
		switch e := err.(type) {
		case sereal.ErrCorrupt:
			log.Fatalf("error processing %s: %s (%s)", fname, e, e.Err)
		default:
			log.Fatalf("error processing %s: %s", fname, e)
		}
	}

	spew.Dump(i)
}
Example #3
0
func unmarshal(b []byte) (intf map[string]interface{}, crash uint64, err error) {

	defer func() {
		if p := recover(); p != nil {
			var stack [5]uintptr
			runtime.Callers(4, stack[:])
			crash = sipuintptr(stack[:])
			err = p.(error)
		}
	}()

	d := sereal.Decoder{}

	err = d.Unmarshal(b, &intf)
	if err != nil {
		return nil, 0, err
	}

	return intf, 0, nil
}
Example #4
0
func main() {

	srlHeader, _ := hex.DecodeString("3d73726c0100")

	var decoder sereal.Decoder
	decoder.PerlCompat = true

	for {
		l := len(srlHeader) + mrand.Intn(200)
		b := make([]byte, l)
		crand.Read(b)
		doc := make([]byte, l+len(srlHeader))
		copy(doc, srlHeader)
		copy(doc[6:], b)
		fmt.Println(hex.Dump(doc))
		var m interface{}
		err := decoder.Unmarshal(doc, &m)
		fmt.Println("err=", err)
	}

}