Closed daohu527 closed 4 months ago
I'm closing this as duplicate of #69. From there:
As you can see in the CDR standard (section 15.3.2.7)
A string is encoded as an unsigned long indicating the length of the string in octets, followed by the string value in single- or multi-byte form represented as a sequence of octets. The string contents include a single terminating null character. The string length includes the null character, so an empty string has a length of 1.
So even when an std::string
may have several \0
characters, a CDR serialized string must only have one, which shall be at the end of the string.
@EduPonz Then my question is a c++ string not equal to spec string. which may lead to invisible errors. I think the forced transition here is not reasonable.
Or similar to gcc, where the specification does not mention, we can handle it flexibly, similar to what the compiler does.
@rojkov
std::string
may contain '\0', so should we pass str.size() toserialize
?https://github.com/eProsima/Fast-CDR/blob/24d9e72f3aa8aab91d2e5e6422f2b5ce90490cb6/include/fastcdr/FastCdr.h#L887-L892
Below is the test code