Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

TList<enumType> is being filled with the zero-value I32's #46

Open
GeertJohan opened this Issue Oct 16, 2012 · 1 comment

Comments

Projects
None yet
1 participant
Contributor

GeertJohan commented Oct 16, 2012

I have a enum definition in a file common.thrift :

enum LogLevel {
    TRACE
    DEBUG
    INFO
    WARN
    ERROR
    FATAL
}

Then there's a struct and a service method in an other file logGet.thrift (including common.thrift):

struct QueryOptions {
    1: required common.LogEnvironment environment,
    2: required list<common.LogLevel> levels, //it's about this list containing the enum value defined in common.thrift
}

service LogGet {
    ResultList simpleGet(1: QueryOptions options);
}

The following generated Go method is where things go wrong (I believe). The method is supposed to read the TList values from the input protocol and push the values to QueryOptions.levels TList
Initially, the method doesn't work. It inserts a zero value (0) for each item that is pushed in the TList.
I found out that it wasn't working because the (TList).Push method verified that the given item has the right type. If not it inserts the zero value for the proper type.
This is done by TType.CoerceData() I believe.. Not sure....
Also, it seems the TList is created for I32 type. So apparently the mismatch between the types common.LogLevel and I32 makes Push() insert zero values.
So I edited the method to work. I commented out the 2 lines that where wrong, and added a line to do the push properly (using the "raw" I32 value).

func (p *QueryOptions) ReadField2(iprot thrift.TProtocol) (err thrift.TProtocolException) {
    _etype23, _size20, err := iprot.ReadListBegin()
    if err != nil {
        return thrift.NewTProtocolExceptionReadField(-1, "p.Levels", "", err)
    }
    p.Levels = thrift.NewTList(_etype23, _size20)  //info: log.Println(_etype23) gives I32
    for _i24 := 0; _i24 < _size20; _i24++ {
        v26, err27 := iprot.ReadI32()
        if err27 != nil {
            return thrift.NewTProtocolExceptionReadField(0, "_elem25", "", err27)
        }
        //_elem25 := common.LogLevel(v26) //wrong
        // p.Levels.Push(_elem25) //wrong
        p.Levels.Push(v26) //good
    }
    err = iprot.ReadListEnd()
    if err != nil {
        return thrift.NewTProtocolExceptionReadField(-1, "", "list", err)
    }
    return err
}
Contributor

GeertJohan commented Oct 16, 2012

I'm working on tests (thrift4go/tests) to reproduce and analyse this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment