-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[c++] Improved field generation #631
Conversation
Added non-const raw access for array like fields
I have merged but this has some issues. What if the string or string view is shorter than the array? The Java codec deals with this by zero padding the remainder and doing a min on the copy for length of view and length of array. |
It's UB. Actually I added |
I think we could add deactivatable via macros check |
Identifying this as UB feels wrong and error prone. The existing string approach was also wrong in this. |
|
@tmontgomery the code is guarded for C++ 17 so only compiled when available. |
And, yes, if the string is short, it should null pad. |
@mjpt777 yes, I understand that. I would, though, say that to avoid noise and the fact that there is very little reason to use it yet that there is no compelling reason to do it at this time. |
@tmontgomery why short string should be null padded? Is string getter should be aware of this (i.e. return string with length less than field length)? |
It probably should be encoding specific what to pad with. And it should be compatible with what Java does right now. The getter is always going to be a specific length. It just may have encoding specific nulls, etc. The setter is the one to determine what to do with the string/string_view is too short. |
The spec example suggests null padding. |
Nice. We can fix cpp generator for string/string_view. What about const char* setter? Calculate string length (strnlen)? Add the second parametr length? template<size_t N> putField(char const (&value)[N]) ? |
I've added length checks and handling via 825e0c4 |
checks for |
Added std::string_view getter/setter for string-like fields
Added non-const raw access for array like fields