dedis / protobuf

Reflection-based Protocol Buffers for Go
GNU General Public License v2.0
76 stars 15 forks source link

Ordering shouldn't matter when specify field numbers #34

Open uluyol opened 7 years ago

uluyol commented 7 years ago

If I have the following test:

type TestMesg struct {
    F1 string            `protobuf:"1,opt"`
    F2 int32             `protobuf:"10,opt"`
    F4 []byte            `protobuf:"99,opt"`
    F3 protobuf.Ufixed64 `protobuf:"14,opt"`
    F5 float64           `protobuf:"108,opt"`
}

func TestEncodeRoundTrip(t *testing.T) {
    m := TestMesg{
        F1: "abasdfasdf312123",
        F2: 109,
        F3: protobuf.Ufixed64(^uint64(0)),
        F4: []byte{0, 12, 44},
        F5: 505.5,
    }

    buf, err := protobuf.Encode(&m)
    if err != nil {
        t.Errorf("unable to encode")
    }

    var m2 TestMesg
    if err := protobuf.Decode(buf, &m2); err != nil {
        t.Errorf("unable to decode")
    }

    if !reflect.DeepEqual(&m, &m2) {
        t.Errorf("written and read msg differ:\nhave %+v\nwant %+v", &m2, &m)
    }
}

Running it fails with

--- FAIL: TestEncodeRoundTrip (0.00s)
    pb_test.go:38: written and read msg differ:
        have &{F1:abasdfasdf312123 F2:109 F4:[0 12 44] F3:0 F5:505.5}
        want &{F1:abasdfasdf312123 F2:109 F4:[0 12 44] F3:18446744073709551615 F5:505.5}

But if I switch the order of F3 and F4 then it passes.