dedis / protobuf

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

Throw error when struct has no serialisable fields #38

Closed kc1212 closed 6 years ago

kc1212 commented 6 years ago

Currently structs with all private fields would get serialised without error, but it would contain no data. We should throw an error instead.

aounleonardo commented 6 years ago

I can see two possible solutions, 1: in Encode, just before returning en.Bytes(), we can check its length, and iff it's 0, it means there were no serializable fields 2: in (en *encoder) message, if no field.CanSet() was true in the loop, we can do something. However, similarly to the issue #30 no other method than Encode can return errors.