Read fixed size strings without padding characters#692
Read fixed size strings without padding characters#692FlyingSamson wants to merge 5 commits intoess-dmsc:masterfrom
Conversation
|
|
||
| AND_GIVEN("an instance of a smaller string") { | ||
| std::string write = "hell"; | ||
| THEN("we have to resize the string to the appropriate size") { |
There was a problem hiding this comment.
Not entirely sure, why this was required in the first place.
From what I understand the code will write shorter strings just fine. This line merely ensured that in the REQUIRE_THAT below write also contained trailing \0 characters.
|
I don't quite have the mental capacity to deal with this on a Friday evening, but I would refer you to my comments on a different PR: ess-dmsc/streaming-data-types#102 (comment)
Surely if it's like to be a different length wouldn't it be better to use |
yuelongyu
left a comment
There was a problem hiding this comment.
Hi @FlyingSamson,
Thanks for the PR.
The datatype::StringPad::NullTerm: I agree, it could be removed. However, the padding part, I think it would be good to stay as it is. It might be not the behavior use expected, user writes the string with space padding intentionally and reads it back with different length. For example, in some protocol, it requires fixed length of commands, so padding is needed. If a user save such a command in file and read it back, the user would expect the command is same as what it's written there.
This would be one way to overcome the current issue that when reading fixed-size strings into
std::strings all padding characters are also returned.This will certainly introduce a certain overhead compared to not trimming the read string (I did not perform any benchmarks though) which need to be contemplated.
On the other hand, in cases where the caller actually wants the trimmed string, forcing him to trim the string himself after it has been created might incur even larger costs.
Resolves #661
Also relevant for #215 and #224