samuel / go-thrift

A native Thrift package for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why are sets mapped to the Go type map[T]interface{}?

cespare opened this issue · comments

I don't understand why the thrift type set<T> is mapped to the Go type map[T]interface{}.

I think that map[T]struct{} is more appropriate -- this map uses 0 bytes for the value and is the most space-efficient representation of a set using Go maps.

An alternative that's a little more convenient is map[T]bool.

Changed it to struct{} in latest master. The reason not bool is because the reflection encoder checks for map[T]struct{} to signify a set. It won't occur in normal use unlike map[T]bool which could and thus requires tagging the field as a set.

The encoding/decoder now support map[T]bool tagged as a set and only including keys where the value is true. This could change to be the default in the future once the code generator is creating static code for the marshall/unmarshall. For now though they rely on the reflection api.