flatbuffers 使用问题记录
1. 命名空间的问题
----------------------------- namespace 1.0.3 版本包含文件类型前面不需要加命名空间,但是1.1.0 中包含需要在类型前加命名空间 include必须放在namespace前面
例如:
include “aa.fbs”
namespace IM.test; foo.fbc
namespace foo;
struct Foo { f: uint; } bar.fbc
include "foo.fbc";
namespace bar;
struct Bar { foo: Foo; } flatc -c bar.fbc will fail with bar.fbc:3:0: error: structs_ may contain only scalar or struct fields 修改方式:
struct Bar { foo: Foo; } -> struct Bar { foo: foo.Foo; } 或者 将 struct 修改成 table struct UserInfo{
user_id:uint;
name:string
} error: structs_ may contain only scalar or struct fields 因为 struct 结构中不能使用 string 类型,修改成 table 即可 2. struct 和 table的区别
------------------------------ http://www.coder4.com/archives/4386
基本类型: 8 bit: byte ubyte bool
16 bit: short ushort
32 bit: int uint float
64 bit: long ulong double 复杂类型: 数组 (用中括号表示 [type]). 不支持嵌套数组,可以用table实现
字符串 string, 支持 UTF-8 或者 7-bit ASCII. 对于其他编码可以用数组 [byte]或者[ubyte]表示。
Struct 只支持基本类型或者嵌套Struct
Table 类似Struct,但是可以支持任何类型。 3. roottype的问题及多个table的解决方式
------------------------------------------ https://github.com/google/flatbuffers/issues/65
Why the need for a Root 1) a commit was pushed yesterday that adds GetRootAs functions for all tables, not just the root_type. 2) generally no. this is a strongly types system, meaning you need to know the kind of buffer you're dealing with. If you want to use this in a context where you want to have multiple different root types, you have these options:
a) make your root type a table that contains a union of all possible sub-roots.
b) prefix flatbuffers with your own file header
c) use flatbuffer's built-in file indentification feature, which hasn't been ported to Java yet. I'll get to that. 3) That's a bug, the 1 should actually read: Any.Monster. I'll fix that. 多个消息一个文件中,但是root_type 只能有一个,解决方式如下:
namespace TestApp; union Msg {TestObj, Hello} struct KV {
key: ulong;
value: double;
} table TestObj {
id:ulong;
name:string;
flag:ubyte = 0;
list:[ulong];
kv:KV;
} table Hello {
id:uint;
name:string;
} table RootMsg{
any:Msg;
} root_type RootMsg; 具体样例可以参见:https://github.com/DavadDi/study_example/tree/master/flatbuffers/multi_table 4. enum不生成name的前缀
--------------------------- flatc -c --no-prefix -b aa.fbs 5. 其他问题
---------------------------- enum的默认值只能从0开始 由于table中的字段全部为可选,因此所有返回指针的地方都必须判断是否为空指针
#define STR(ptr) (ptr!=nullptr)?ptr->c_str():""
std::string = STR(user_info->user_name());
flatbuffers 使用问题记录的更多相关文章
- Protocol Buffers与FlatBuffers效率对比
Protocol Buffers是Google跨语言.跨平台的通用序列化库.FlatBuffers同样出自Google,而且也跨语言跨平台,但更强调效率,专门为游戏开发打造.在游戏界混了几年,各种各样 ...
- 在Android中使用FlatBuffers(中篇)
本文来自网易云社区. FlatBuffers.Protobuf及JSON对比测试 FlatBuffers相对于Protobuf的表现又如何呢?这里我们用数据说话,对比一下FlatBuffers格式.J ...
- 在Android中使用FlatBuffers(下篇)
本文来自网易云社区. FlatBuffers编码数组 编码数组的过程如下: 先执行 startVector(),这个方法会记录数组的长度,处理元素的对齐,准备足够的空间,并设置nested,用于指示记 ...
- Flatbuffers学习
flatbuffers简介 FlatBuffers 是一个(二进制 buffer)序列化开源库,由 Google 开源现在它支持C++, C#, C, Go, Java, Kotlin, JavaSc ...
- 记一次debug记录:Uncaught SyntaxError: Unexpected token ILLEGAL
在使用FIS3搭建项目的时候,遇到了一些问题,这里记录下. 这里是发布搭建代码: // 代码发布时 fis.media('qa') .match('*.{js,css,png}', { useHash ...
- nginx配置反向代理或跳转出现400问题处理记录
午休完上班后,同事说测试站点访问接口出现400 Bad Request Request Header Or Cookie Too Large提示,心想还好是测试服务器出现问题,影响不大,不过也赶紧上 ...
- Kali对wifi的破解记录
好记性不如烂笔头,记录一下. 我是在淘宝买的拓实N87,Kali可以识别,还行. 操作系统:Kali 开始吧. 查看一下网卡的接口.命令如下 airmon-ng 可以看出接口名称是wlan0mon. ...
- 2015 西雅图微软总部MVP峰会记录
2015 西雅图微软总部MVP峰会记录 今年决定参加微软MVP全球峰会,在出发之前本人就已经写这篇博客,希望将本次会议原汁原味奉献给大家 因为这次是本人第一次写会议记录,写得不好的地方希望各位园友见谅 ...
- 分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间)
分享一个SQLSERVER脚本(计算数据库中各个表的数据量和每行记录所占用空间) 很多时候我们都需要计算数据库中各个表的数据量和每行记录所占用空间 这里共享一个脚本 CREATE TABLE #tab ...
随机推荐
- ehcache整合spring注解方式
一.简介 在hibernate中就是用到了ehcache 充当缓存.spring对ehcache也提供了支持,使用也比较简单,只需在spring的配置文件中将ehcache的ehcache.xml文件 ...
- hdu 1398 Square Coins(简单dp)
Square Coins Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Pro ...
- android自定义radiobutton样式文字颜色随选中状态而改变
主要是写一个 color selector 在res/建一个文件夹取名color res/color/color_radiobutton.xml <selector xmlns:android= ...
- SQOOP Load Data from Oracle to Hive Table
sqoop import -D oraoop.disabled=true \ --connect "jdbc:oracle:thin:@(description=(address=(prot ...
- 3D俄罗斯方块设计
发布在博客:http://blog.sina.com.cn/s/blog_d38e811c0101cpis.html
- On Perseverance
Brothers,I dont consider that I have made it my own.But one thing I do:forgetting what lies behind a ...
- ZOJ 1109 Language of FatMouse
较简单字典树,每输入一对字符串,前一个放在字典(数组)中,后一个插入字典树中,并将其最终的flag赋为前一个在数组中的下标,再就好找了.输入的处理方法要注意一下. 代码: #include <i ...
- 发布资源到Asset Store
导入unitypackage右上角没有图标? 每当导入从Asset Store下载的资源时,总会看到右侧有个ICON 而我们自己导出的*.unitypackage ,当我们再次导入时,在右侧就没有此图 ...
- Mecanim的Retargeting和BodyMask
Retargeting(动画重定向) 文档 http://game.ceeger.com/Manual/Retargeting.html 介绍 Mecanim 的最强大的功能之一,重定目标的仿人机器人 ...
- Jira-Clone与发邮件的使用
1.克隆问题 包括两部分,先进行Clone,再进行移动 a.选择要克隆的问题,点击More Actions-Clone,在弹出框“复制问题”中,点击“创建”按钮即克隆成功 b.移动问题,点击More ...