`...ByKey()` returns Kotlin flatbuffers impl 中的 null
`...ByKey()` returns null in Kotlin flatbuffers impl
我有以下架构:
...
table FiltersByDomain {
domain: string (key);
filters: [FilterIsIncluded] (required);
}
table Index {
...
filters_by_domain: [FiltersByDomain];
...
}
root_type Index;
当我按索引使用 getter 并收集键时,我能够找到一些值:
val domains = mutableMapOf<String, Int>()
for (i in 0 until index.filtersByDomainLength) {
val pair = index.filtersByDomain(i)!!
domains[pair.domain!!] = pair.filtersLength
}
assertTrue(domains.keys.contains("scifinow.co.uk"))
val someDomain = "dcw50.com"
assertEquals(3, domains[someDomain]) // succeeds
如果我使用生成的 ..ByKey
方法 returns null
:
assertEquals(3, index.filtersByDomainByKey(someDomain)!!.filtersLength) // fails
这是 test(在 Android 上)。
PS。
使用 api 'com.google.flatbuffers:flatbuffers-java:1.12.0'
,文件是用 flatc --kotlin -o ../java schema.fbs
生成的
PPS。出于好奇,我尝试使用 flatc --java -o ../java schema.fbs
Java 类 生成,但它也失败了。
> flatc --version
flatc version 1.12.0
包含表的向量需要在序列化之前按 key
字段排序,以便使用 ByKey
方法进行查找(它是作为二进制搜索实现的,因为 FlatBuffers 在就地零拷贝格式,查找也就地发生,而不是在目的地构建字典)。
我有以下架构:
...
table FiltersByDomain {
domain: string (key);
filters: [FilterIsIncluded] (required);
}
table Index {
...
filters_by_domain: [FiltersByDomain];
...
}
root_type Index;
当我按索引使用 getter 并收集键时,我能够找到一些值:
val domains = mutableMapOf<String, Int>()
for (i in 0 until index.filtersByDomainLength) {
val pair = index.filtersByDomain(i)!!
domains[pair.domain!!] = pair.filtersLength
}
assertTrue(domains.keys.contains("scifinow.co.uk"))
val someDomain = "dcw50.com"
assertEquals(3, domains[someDomain]) // succeeds
如果我使用生成的 ..ByKey
方法 returns null
:
assertEquals(3, index.filtersByDomainByKey(someDomain)!!.filtersLength) // fails
这是 test(在 Android 上)。
PS。
使用 api 'com.google.flatbuffers:flatbuffers-java:1.12.0'
,文件是用 flatc --kotlin -o ../java schema.fbs
PPS。出于好奇,我尝试使用 flatc --java -o ../java schema.fbs
Java 类 生成,但它也失败了。
> flatc --version
flatc version 1.12.0
包含表的向量需要在序列化之前按 key
字段排序,以便使用 ByKey
方法进行查找(它是作为二进制搜索实现的,因为 FlatBuffers 在就地零拷贝格式,查找也就地发生,而不是在目的地构建字典)。