thriftrw / thriftrw-node

A thrift binary encoding library using bufrw
MIT License
57 stars 25 forks source link

How to annotate set<i64> and map<x, i64> in thrift definition files? #159

Closed lxe closed 6 years ago

lxe commented 6 years ago

What's the proper way to annotate the map<string, i64> and set<i64> types? Doing

map<string, i64> (js.type = "Long") 

generates this error:

.../node_modules/thriftrw/map.js:41
        throw errors.UnexpectedMapTypeAnnotation({
        ^

ThriftUnexpectedMapTypeAnnotationError: unexpected map js.type annotation "Long"
    at Object.createError [as UnexpectedMapTypeAnnotation] (.../node_modules/error/typed.js:31:22)

while

set<i64> (js.type = "Long")

generates this error:

assert.js:42
  throw new errors.AssertionError({
  ^

AssertionError [ERR_ASSERTION]: set must have js.type of object or array (default)
    at new ThriftSet (/.../node_modules/thriftrw/set.js:56:16)
abhinav commented 6 years ago

You should be able to do,

map<string, i64 (js.type = "Long")>
set<i64 (js.type = "Long")>

Or better yet, declare a typedef and use that.

typedef i64 (js.type = "Long") Long

Then,

map<string, Long>
set<Long>
lxe commented 6 years ago

Thank you @abhinav. This worked