I have some data stored in Redis which is saved by python app by pickling the data. So basically this is a pickled python dict object. I want to get this stored data in golang. I found a library : https://godoc.org/github.com/hydrogen18/stalecucumber
But when I try some basic example to do unpickling its giving errors like:
string:Pickle Machine failed on opcode:0x62. Stack size:0. Memo size:0. Cause:Stack is too small to perform requested operation
string:Pickle Machine failed on opcode:0x5c. Stack size:0. Memo size:0. Cause:Opcode is invalid
For more clarification refer example given below.
-
Data = pickle.dumps({"apple":1,"banana":2,"cat":"hello","Dog":42.0})
#python pickling - Pickled data =
b'\x80\x03}q\x00(X\x05\x00\x00\x00appleq\x01K\x01X\x06\x00\x00\x00bananaq\x02K\x02X\x03\x00\x00\x00catq\x03X\x05\x00\x00\x00helloq\x04X\x03\x00\x00\x00Dogq\x05G@E\x00\x00\x00\x00\x00\x00u.'
My try to unpickle in Go:
package main
import (
"fmt"
"stalecucumber"
"io"
"os"
)
func main() {
var pickledDict io.Reader
var err error
pickledDict, err = os.Open("file.txt")
fmt.Println(pickledDict)
mystruct := struct{
Apple int
Banana uint
Cat string
Dog float32
}{}
err = stalecucumber.UnpackInto(&mystruct).From(stalecucumber.Unpickle(pickledDict))
if err != nil {
fmt.Println(err)
}
fmt.Println(mystruct)
}
Getting Error:
Pickle Machine failed on opcode:0x62. Stack size:0. Memo size:0. Cause:Stack is too small to perform requested operation
{0 0 0}