<p>Hi all, I am having issues with flatbuffers that are written in Go and segfaulting in C++. In Go, I can read C++ written flatbuffers file. But for in C++, it segfaluts trying to read a Go-written flatbuffers file. </p>
<p>I have 2 questions:
1. Has anyone tried doing this before and succeeded? C++ generated flatbuffers code is a lot more than the Go equivalent.
2. I'd be happy to share the fbs file and the code if it helps but didn't want to spam the forum.</p>
<p>Thanks!</p>
<hr/>**评论:**<br/><br/>_zchee_: <pre><p>it means, dump fbs binary with C++ and Go. but C++ can't read Go's generated binary?
I don't know C++implementation, but I have Go's project that using flatbuffer for libclang, and dump data into leveldb.
<a href="https://github.com/zchee/clang-server" rel="nofollow">https://github.com/zchee/clang-server</a></p>
<p>So I might be able to help you.</p></pre>echophant: <pre><p>Knowing very little about Flatbuffers (but being familiar with Cap'n Proto and Protocol Buffers), I would think that the same data serialized in C++ and Go should be bit-for-bit identical.</p>
<p>That would make me think that the issue is that the data isn't being read from file correctly, perhaps being parsed as text instead of binary. Sharing the data/code might help here.</p></pre>therealfakemoot: <pre><p>I thought the same thing, but the Flatbuffers specification actually allows the serializer to control the ordering of fields to allow for {back,for}wards compatibility. So, technically, you can't rely on doing a byte-for-byte diff to compare a flatbuffer payload on-the-wire, since the ordering of member fields is not defined. My lack of better ideas is why I didn't post earlier.</p></pre>zhenjl: <pre><p>Hi all, I figured out my issue finally. I was pushing the offsets to a slice declared as</p>
<pre><code>var treeOffsets, nodeOffsets []flatbuffers.UOffsetT
</code></pre>
<p>And for some reason appending to these didn't take, and I had to change to</p>
<pre><code>treeOffsets := make([]flatbuffers.UOffsetT, 0)
nodeOffsets := make([]flatbuffers.UOffsetT, 0)
</code></pre>
<p>And this fixed it. I thought append will allocate a new slice if there's no room, but I may have misunderstood how it works.</p>
<p>The final output is still not exactly the same for the 2 languages, but as <a href="/u/therealfakemoot" rel="nofollow">/u/therealfakemoot</a> said, the two may not be byte-to-byte the same anyway. </p></pre>noonexx: <pre><p>Please keep in mind, that you still have the segfault in the C++ code. I strongly suggest fixing it, if it is anywhere near production use. In the best case, one could send broken data to perform a denial of service attack.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传