英文:
How do I decode an Apache Thrift payload in Go?
问题
这是我正在尝试在Go中实现的工作中的JavaScript版本。
let next = TBufferedTransport.receiver(data => {
let proto = new TCompactProtocol(data);
let ae = new AnalyticEventBatch();
ae.read(proto);
});
在Go中,我无法使Thrift解码有效载荷 - 我应该做什么?
英文:
This is the working JavaScript version of what I'm trying to do in Go.
let next = TBufferedTransport.receiver(data => {
let proto = new TCompactProtocol(data)
let ae = new AnalyticEventBatch()
ae.read(proto)
});
Using Go, I can't get Thrift to decode the payload - what should I be doing?
答案1
得分: 4
var data []byte //这是你接收到的字节数组
transp := &TMemoryBuffer{Buffer: bytes.NewBuffer(data)}
proto := NewTCompactProtocol(transp)
ae := NewAnalyticEventBatch()
ae.Read(proto)
如果你可以直接从文件/套接字中读取,会更加清晰。那样的话,你只需要使用 thrift 的 StreamTransport
。
英文:
var data []byte //that's the byte array you received
transp := &TMemoryBuffer{Buffer: bytes.NewBuffer(data)}
proto := NewTCompactProtocol(transp)
ae := NewAnalyticEventBatch()
ae.Read(proto)
It would be cleaner if you could read from file/socket directly. Then you would only need thrift StreamTransport
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论