我有一些数据存储在 Redis 中,这些数据由 python 应用程序通过酸洗数据来保存。所以基本上这是一个腌制的python dict 对象。我想在 golang 中获取这些存储的数据。我找到了一个图书馆:https ://godoc.org/github.com/hydrogen18/stalecucumber
但是,当我尝试一些基本示例来解开其给出的错误时,例如:
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
有关更多说明,请参阅下面给出的示例。
Data = pickle.dumps({"apple":1,"banana":2,"cat":"hello","Dog":42.0})
#python酸洗- 腌制数据=
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.'
我尝试在 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)
}
得到错误:
Pickle Machine failed on opcode:0x62. Stack size:0. Memo size:0. Cause:Stack is too small to perform requested operation
{0 0 0}