szaszm commented on code in PR #2251:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2251#discussion_r3903339239
##########
core-framework/common/src/io/InputStream.cpp:
##########
@@ -47,44 +49,51 @@ size_t InputStream::read(utils::Identifier &value) {
return ret;
}
-size_t InputStream::read(std::string &str, bool widen) {
+size_t InputStream::read(std::string &str, LengthPrefixSize prefix_size,
size_t max_length) {
uint32_t string_length = 0;
- size_t length_return = 0;
- if (!widen) {
- uint16_t shortLength = 0;
- length_return = read(shortLength);
- string_length = shortLength;
- } else {
- length_return = read(string_length);
+ size_t length_prefix_size_in_bytes = 0;
+ switch (prefix_size) {
+ case LengthPrefixSize::_16BIT: {
+ uint16_t out_16bit_length = 0;
+ length_prefix_size_in_bytes = read(out_16bit_length);
+ string_length = out_16bit_length;
+ } break;
+ case LengthPrefixSize::_32BIT: {
+ uint32_t out_32bit_length = 0;
+ length_prefix_size_in_bytes = read(out_32bit_length);
+ string_length = out_32bit_length;
+ } break;
}
- if (length_return == 0 || isError(length_return)) {
- return length_return;
+ // The zero case should be impossible, read(Integral&) returns the size of
the integral type,
+ // or an error code, so this handles the error case and propagates the
stream error
+ if (length_prefix_size_in_bytes == 0 ||
isError(length_prefix_size_in_bytes)) {
+ return length_prefix_size_in_bytes;
}
+ string_length = std::min(string_length, gsl::narrow<uint32_t>(max_length));
if (string_length == 0) {
str.clear();
- return length_return;
+ return length_prefix_size_in_bytes;
}
str.clear();
- str.reserve(string_length);
+ str.resize(string_length);
+ std::span<std::byte> dst_buffer = as_writable_bytes(std::span{str});
Review Comment:
https://en.cppreference.com/cpp/container/span/span#Version_7
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]