我用Thrift 0.9.1实验了golang生成,例如,
节俭定义,
struct AppIdLeveledHashKeyTimeKeyHour {
1: required i32 appId
2: required LeveledHashKey leveledHashKey
3: required TimeKeyHour timeKeyHour
}
typedef map<AppIdLeveledHashKeyTimeKeyHour, ...sth else...> EventSliceShardIdValue
在生成的代码中,EventSliceShardIdValue将是
type EventSliceShardIdValue map[*AppIdLeveledHashKeyTimeKeyHour]EventSliceAppIdLeveledHashKeyTimeKeyHourValue
你可以找到关键部分是一个代表内存地址的指针。在golang中,指针作为映射键(而不是obj的值或散列)在大多数情况下是无用的。要将某些字段的组合用作映射键,定义应使用类似
的值类型map[AppIdLeveledHashKeyTimeKeyHour]EventSliceAppIdLeveledHashKeyTimeKeyHourValue
这是Thrift的支持(或者我误用了)的问题吗?在节俭中解决这个问题的任何解决方法?
答案 0 :(得分:0)
结构(没有指针)只能在某些有限的情况下用作地图键(它们必须按照http://golang.org/ref/spec#Comparison_operators进行比较); AppIdLeveledHashKeyTimeKeyHour
可能不符合此定义,因此实际上不使用指针来构建映射。