Skip to content

Instantly share code, notes, and snippets.

@methane
Created January 29, 2015 07:30
Show Gist options
  • Save methane/bffc908568deb96c2a27 to your computer and use it in GitHub Desktop.
Save methane/bffc908568deb96c2a27 to your computer and use it in GitHub Desktop.
Can't encode RawExt
package main
import (
"fmt"
"github.com/ugorji/go/codec"
)
var mh = codec.MsgpackHandle{}
func main() {
mh.SignedInteger = false
data := []byte{0xd4, 42, 84}
dec := codec.NewDecoderBytes(data, &mh)
var dd interface{}
dec.MustDecode(&dd)
fmt.Printf("%+v, %T\n", dd, dd)
out := []byte{}
enc := codec.NewEncoderBytes(&out, &mh)
enc.MustEncode(dd)
fmt.Printf("%x\n", out)
}
$ go run codec.go
{Tag:42 Data:[84] Value:<nil>}, codec.RawExt
panic: interface conversion: interface is codec.RawExt, not *codec.RawExt
goroutine 1 [running]:
github.com/ugorji/go/codec.encFnInfo.rawExt(0x927568, 0xc20803be00, 0xc20803bef0, 0x4d0d20, 0xc20803bdd0, 0x59)
/Users/inada-n/go1.4/src/github.com/ugorji/go/codec/encode.go:275 +0x7e
github.com/ugorji/go/codec.(*Encoder).encodeI(0xc20804cbe0, 0x4d0d20, 0xc20803bdd0, 0x0)
/Users/inada-n/go1.4/src/github.com/ugorji/go/codec/encode.go:953 +0x1df
github.com/ugorji/go/codec.(*Encoder).encode(0xc20804cbe0, 0x4d0d20, 0xc20803bdd0)
/Users/inada-n/go1.4/src/github.com/ugorji/go/codec/encode.go:943 +0x340
github.com/ugorji/go/codec.(*Encoder).MustEncode(0xc20804cbe0, 0x4d0d20, 0xc20803bdd0)
/Users/inada-n/go1.4/src/github.com/ugorji/go/codec/encode.go:844 +0x3c
main.main()
/Users/inada-n/t/codec.go:24 +0x2d5
exit status 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment