英文:
Receiving a pickled stream in golang
问题
我有一个使用Golang编写的TCP服务器,想要接收和解码一个pickle流。
我正在使用stalecucumber来在Go中进行反pickle操作。
Python端的代码大致如下:
sock = socket(AF_INET,SOCK_STREAM)
sock.connect(('127.0.0.1',5006))
sock.send(cPickle.dumps(data))
Go服务器的代码如下:
ln, _ := net.Listen(CONN_TYPE, CONN_PORT)
conn, _ := ln.Accept()
data := make([]byte,0)
for {
// 对于gob,我通常会这样做
// dec.Decode(&data);
err := stalecucumber.UnpackInto(&data).From(stalecucumber.Unpickle(<无法在此处提供conn>))
}
有没有办法监听pickle对象的流并对其进行解码?
英文:
I have my tcp server in golang and would like to receive and decode a pickled stream
I am using stalecucumber to unpickle data in go
The python side roughly looks like this
sock = socket(AF_INET,SOCK_STREAM)
sock.connect(('127.0.0.1',5006))
sock.send(cPickle.dumps(data))
The Go server looks like this:
ln, _ := net.Listen(CONN_TYPE, CONN_PORT)
conn, _ := ln.Accept()
data := make([]byte,0)
for {
// for gob I would normally do this
// dec.Decode(&data);
err := stalecucumber.UnpackInto(&data).From(stalecucumber.Unpickle(<can't provide conn here>))
}
Any way to listen to a stream of pickled objects and decode them ?
答案1
得分: 1
>来自stalecucumber
>Unpickle
需要一个io.Reader
>
func Unpickle(reader io.Reader) (interface{}, error) {
>应该是这样的:
>
err = UnpackInto(&data).From(Unpickle(bytes.NewReader(buf.Bytes())))
我猜你需要在conn
上使用它
err = UnpackInto(&data).From(Unpickle(bytes.NewReader(conn)))
英文:
>From stalecucumber
>Unpickle
needs a io.reader
>
func Unpickle(reader io.Reader) (interface{}, error) {
>Should look like that:
>
err = UnpackInto(&data).From(Unpickle( bytes.NewReader( buf.Bytes() ) ))
I assume you have to use it with conn
err = UnpackInto(&data).From(Unpickle( bytes.NewReader( conn ) ))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论