protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Only rename size fields if sizer is enabled.

Open devnev opened this issue 7 years ago • 6 comments

The Size method is only created if the sizer plugin is enabled, and other parts of the codebase seem to handle this case. The helpers here were assuming that either Size or ProtoSize exists, which is not true, especially if the base message was generated with the google golang plugin.

devnev avatar Aug 11 '17 11:08 devnev

Could you add a test that shows how it broke before this change? So that we don't regress in future.

awalterschulze avatar Aug 11 '17 12:08 awalterschulze

hello?

awalterschulze avatar Oct 07 '17 14:10 awalterschulze

I would like to volunteer my help in getting this merged. This is a necessary change for our continued use of the library. What sort of test are you looking for? Is there an existing example exercising another feature that might work as a basis? Essentially what the test(s) would do is ensure there is no Size and GetSize() created when sizer is not used.

schleppy avatar Apr 15 '19 16:04 schleppy

Hi, Thanks for volunteering. I didn't look at this issue initially, but correct me if I am wrong. I think the issue is we assume we are generating a Size() method, even without enabling the gogo-option. This means we will always substitute fields Size -> Size_.

Is there an existing example exercising another feature that might work as a basis? What sort of test are you looking for?

Here an example of tests involving Size and ProtoSize.

protosize

You could create a similar tests and assert the resulting structure has the expected methods/fields with the combination of the sizer_all,protosizer_all, no size options? That would assert that the generation of the structs are as expected with the relevant size options?

Essentially what the test(s) would do is ensure there is no Size and GetSize() created when sizer is not used. Yeh

jmarais avatar Apr 17 '19 08:04 jmarais

does it possible to not modify struct member Size to Size_ ?i need to expose this member as-is with name Size.

vtolstov avatar Jun 26 '19 09:06 vtolstov

Anyone can fix it? I need this too.

option (gogoproto.protosizer_all) = true;
option (gogoproto.sizer_all) = false;

No matter, enable protosizer and disable sizer works for me.

icefed avatar Nov 05 '20 09:11 icefed