Closed anxiousmodernman closed 8 years ago
This is a tough call. While technically Thrift does define byte (thus binary) being a signed bye, this feels the case only because it started life in Java which only has signed types. The most used case for byte/binary I've seen in Thrift is for binary data which is awkward if using int8. It feels most useful, though potentially not totally following the "spec", to use byte instead of int8. It seems rare to actually want signed 8-bit integers except for perhaps signed 8-bit PCM audio.
For the record, a straight-up find/replace in the code generated by go-thrift made my integration tests pass against a Java service expecting a Java byte array byte[]
. So, unless I'm missing something, a flag could be passed to the generator that would force this behavior.
[]byte ---> []int8
Would you be willing to accept a PR that simply emits []int8
instead of []byte
if a flag is passed? Maybe something like -go.signedbytes
:
$ generator --help
Usage of parsimony: [options] inputfile outputpath
-go.binarystring=false: Always use string for binary instead of []byte
-go.json.enumnum=false: For JSON marshal enums by number instead of name
-go.pointers=false: Make all fields pointers
-go.signedbytes=false: Interpret Thrift byte as signed int8 type
$ generator cassandra.thrift $GOPATH/src/
Yeah, that sounds good, and definitely nice to give people the choice.
@samuel I think we can close this now
According to this doc:
https://diwakergupta.github.io/thrift-missing-guide/#_types
The Thrift
byte
type is a signed type. My understanding is that Go'sbyte
is an alias to unsigneduint8
.Using go-thrift, I get the following transformation:
Thrift method signature
Interface go-thrift generated
The Apache go thrift library generated the following, as a reference:
I noticed this when interoperating with a Java service via Thrift. In Java, the
byte
type is a signed 8 bit integer.