You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "jduo (via GitHub)" <gi...@apache.org> on 2023/11/01 16:42:21 UTC

Re: [PR] GH-34865: [C++][Flight RPC] Add Session management messages [arrow]

jduo commented on code in PR #34817:
URL: https://github.com/apache/arrow/pull/34817#discussion_r1379044557


##########
cpp/src/arrow/flight/serialization_internal.cc:
##########
@@ -372,6 +372,174 @@ Status ToPayload(const FlightDescriptor& descr, std::shared_ptr<Buffer>* out) {
   return Status::OK();
 }
 
+// SessionOptionValue
+
+Status FromProto(const pb::SessionOptionValue& pb_val
+                                     SessionOptionValue* val) {
+  switch (pb_opt_val.option_value_case()) {
+    case pb::SessionOptionValue::OPTION_VALUE_NOT_SET:
+      return Status::Invalid("Unset option_value for name '" +
+                             pb_opt_name + "'");
+    case pb::SessionOptionValue::kStringValue:
+      val = pb_opt_val.string_value();
+      break;
+    case pb::SessionOptionValue::kBoolValue:
+      val = pb_opt_val.bool_value();
+      break;
+    case pb::SessionOptionValue::kInt32Value:
+      val = pb_opt_val.int32_value();
+      break;
+    case pb::SessionOptionValue::kInt64Value:
+      val = pb_opt_val.int64_value();
+      break;
+    case pb::SessionOptionValue::kFloatValue:
+      val = pb_opt_val.float_value();
+      break;
+    case pb::SessionOptionValue::kDoubleValue:
+      val = pb_opt_val.double_value();
+      break;
+    case pb::SessionOptionValue::kStringListValue:
+      val.emplace<std::vector<std::string>>();
+      std::get<std::vector<std::string>>(val)
+          .reserve(pb_opt_val.string_list_value().values_size());
+      for (const std::string& s : pb_opt_val.string_list_value().values())
+        std::get<std::vector<std::string>>(val).push_back(s);
+      break;
+  }
+  return Status::OK();
+}
+
+Status ToProto(const SessionOptionValue& val
+                                       pb::SessionOptionValue pb_val) {
+  std::visit(overloaded{
+      [&](std::string v) { pb_val.set_string_value(v); },
+      [&](bool v) { pb_val.set_bool_value(v); },
+      [&](int32_t v) { pb_val.set_int32_value(v); },
+      [&](int64_t v) { pb_val.set_int64_value(v); },
+      [&](float v) { pb_val.set_float_value(v); },
+      [&](double v) { pb_val.set_double_value(v); },
+      [&](std::vector<std::string> v) {
+        auto* string_list_value = pb_val.mutable_string_list_value();
+        for (const std::string& s : v)
+          string_list_value->add_values(s);
+      }
+    }, opt_value);
+  return Status::OK();
+}
+
+// map<string, SessionOptionValue>
+
+Status FromProto(const google::protobuf::map<string,
+                                             pb::SessionOptionValue> pb_map,   //PHOXME maybe need to include google/protobuf/map.h ?  shouldn't this be brought in by other headers?
+                 std::map<std::string, SessionOptionValue>* map) {
+  if (pb_map.size() == 0) {

Review Comment:
   Is there a .empty() function that can be called instead?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org