如何在Go中解码Apache Thrift有效负载?

时间:2016-03-01 17:36:09

标签: go thrift

这是我在Go中尝试做的JavaScript版本。

let next = TBufferedTransport.receiver(data => {

 let proto = new TCompactProtocol(data)
 let ae = new AnalyticEventBatch()

 ae.read(proto)
});

使用Go,我无法让Thrift解码有效载荷 - 我应该怎么做?

1 个答案:

答案 0 :(得分:4)

var data []byte //that's the byte array you received

transp := &TMemoryBuffer{Buffer: bytes.NewBuffer(data)}
proto := NewTCompactProtocol(transp)

ae := NewAnalyticEventBatch()
ae.Read(proto)

如果你可以直接从文件/套接字读取它会更干净。那么你只需要节俭StreamTransport