在golang中接收一个pickled流

huangapple go评论95阅读模式
英文:

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((&#39;127.0.0.1&#39;,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(&amp;data); 
    err := stalecucumber.UnpackInto(&amp;data).From(stalecucumber.Unpickle(&lt;can&#39;t provide conn here&gt;))
}

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(&amp;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(&amp;data).From(Unpickle( bytes.NewReader( conn ) ))  

huangapple
  • 本文由 发表于 2017年5月11日 19:04:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/43913579.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定