adamdebreceni commented on code in PR #2148:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2148#discussion_r3085157640
##########
minifi-api/common/include/minifi-cpp/io/StreamCallback.h:
##########
@@ -16,24 +16,100 @@
*/
#pragma once
+#include <cinttypes>
#include <functional>
#include <memory>
-#include <optional>
+
+#include "../../minifi-api/include/minifi-c/minifi-c.h"
+#include "Stream.h"
+#include "minifi-cpp/utils/gsl.h"
+#include "utils/expected.h"
namespace org::apache::nifi::minifi::io {
class InputStream;
class OutputStream;
-struct ReadWriteResult {
- int64_t bytes_written = 0;
- int64_t bytes_read = 0;
+class IoResult {
+ public:
+ IoResult() = delete;
+ IoResult(const IoResult&) = default;
+ IoResult(IoResult&&) noexcept = default;
+ IoResult& operator=(IoResult&&) noexcept = default;
+ IoResult& operator=(const IoResult&) = default;
+
+ virtual ~IoResult() = default;
+
+ static IoResult error() { return
IoResult(nonstd::make_unexpected(MINIFI_IO_ERROR)); }
+ static IoResult cancelled() { return
IoResult(nonstd::make_unexpected(MINIFI_IO_CANCEL)); }
+ static IoResult zero() { return IoResult(0U); }
+
+ static IoResult fromI64(int64_t i64_val) {
+ if (i64_val < 0) { return
IoResult(nonstd::make_unexpected(static_cast<MinifiIoStatus>(i64_val))); }
+ return IoResult(gsl::narrow<uint64_t>(i64_val));
+ }
+
+ static IoResult fromSizeT(const size_t val) {
+ if (isError(val)) { return IoResult::error(); }
+ return IoResult(gsl::narrow<uint64_t>(val));
+ }
Review Comment:
I think we should either clarify how these differ (usage wise) and let that
be reflected in the name or drop the type from the name (or if we want to
prevent casts we could move to a template and branch with std::is_same_v and
friends)
--
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]