szaszm commented on code in PR #1863:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1863#discussion_r1793167039
##########
extensions/python/types/PyProcessSession.h:
##########
@@ -39,10 +39,11 @@ class PyProcessSession {
void remove(const std::shared_ptr<core::FlowFile>& flow_file);
std::string getContentsAsString(const std::shared_ptr<core::FlowFile>&
flow_file);
void putAttribute(const std::shared_ptr<core::FlowFile>& flow_file,
std::string_view key, const std::string& value);
+ core::ProcessSession& getSession() const { return session_; }
private:
std::vector<std::shared_ptr<core::FlowFile>> flow_files_;
- gsl::not_null<core::ProcessSession*> session_;
+ core::ProcessSession& session_;
Review Comment:
For non-static data members, mutable types like
`gsl::not_null<core::ProcessSession*>` usually work better than immutable like
`core::ProcessSession&`, because immutable members disable move and
reassignment. Everywhere else, a reference is usually better.
If this type is only ever used on the heap, without move or reassignment,
then it can be fine, so I leave it up to you, but I'd still revert it, just to
keep things simple and consistent.
##########
libminifi/src/core/RecordField.cpp:
##########
@@ -0,0 +1,99 @@
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "core/RecordField.h"
+
+#include "utils/GeneralUtils.h"
+#include "utils/TimeUtil.h"
+
+namespace org::apache::nifi::minifi::core {
+
+rapidjson::Value RecordField::toJson(rapidjson::Document::AllocatorType&
allocator) const {
+ rapidjson::Value value;
+ std::visit(utils::overloaded {
+ [&value, &allocator](const std::string& str) {
+ value.SetString(str.c_str(), allocator);
+ },
+ [&value](int64_t i64) {
+ value.SetInt64(i64);
+ },
+ [&value](uint64_t u64) {
+ value.SetUint64(u64);
+ },
+ [&value](double d) {
+ value.SetDouble(d);
+ },
+ [&value](bool b) {
+ value.SetBool(b);
+ },
+ [&value, &allocator](const std::chrono::system_clock::time_point&
time_point) {
+
value.SetString(utils::timeutils::getDateTimeStr(std::chrono::time_point_cast<std::chrono::seconds>(time_point)).c_str(),
allocator);
+ },
+ [&value, &allocator](const RecordArray& arr) {
+ value.SetArray();
+ for (const auto& elem : arr) {
+ rapidjson::Value elem_value = elem.toJson(allocator);
+ value.PushBack(elem_value, allocator);
+ }
+ },
+ [&value, &allocator](const RecordObject& obj) {
+ value.SetObject();
+ for (const auto& [key, boxed_field] : obj) {
+ rapidjson::Value keyValue;
+ keyValue.SetString(key.c_str(), allocator);
+
+ rapidjson::Value fieldValue = boxed_field.field->toJson(allocator);
+ value.AddMember(keyValue, fieldValue, allocator);
+ }
+ }
+ }, value_);
+
+ return value;
+}
+
+RecordField RecordField::fromJson(const rapidjson::Value& value) {
+ if (value.IsString()) {
+ std::string str_value = value.GetString();
+ if (auto test_time = utils::timeutils::parseDateTimeStr(str_value)) {
+ return RecordField(std::chrono::time_point{*test_time});
+ }
+ return RecordField(str_value);
+ } else if (value.IsInt64()) {
+ return RecordField(value.GetInt64());
+ } else if (value.IsUint64()) {
Review Comment:
I'd use brace init with our types too, not just standard ones.
--
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]