lidavidm commented on code in PR #34817:
URL: https://github.com/apache/arrow/pull/34817#discussion_r1406609476
##########
cpp/src/arrow/flight/serialization_internal.cc:
##########
@@ -376,6 +384,161 @@ 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_val.option_value_case()) {
+ case pb::SessionOptionValue::OPTION_VALUE_NOT_SET:
+ return Status::Invalid("Unset SessionOptionValue found");
+ case pb::SessionOptionValue::kStringValue:
+ *val = pb_val.string_value();
+ break;
+ case pb::SessionOptionValue::kBoolValue:
+ *val = pb_val.bool_value();
+ break;
+ case pb::SessionOptionValue::kInt32Value:
+ *val = pb_val.int32_value();
+ break;
+ case pb::SessionOptionValue::kInt64Value:
+ *val = pb_val.int64_value();
+ break;
+ case pb::SessionOptionValue::kFloatValue:
+ *val = pb_val.float_value();
+ break;
+ case pb::SessionOptionValue::kDoubleValue:
+ *val = pb_val.double_value();
+ break;
+ case pb::SessionOptionValue::kStringListValue:
+ (*val).emplace<std::vector<std::string>>();
+ std::get<std::vector<std::string>>(*val).reserve(
+ pb_val.string_list_value().values_size());
+ for (const std::string& s : pb_val.string_list_value().values())
+ std::get<std::vector<std::string>>(*val).push_back(s);
Review Comment:
nit: use explicit braces (and wrap the entire `case` in braces since this
one is more complicated)
Presumably, you could also construct the vector outside the optional, then
move it into the optional as well to simplify things a bit
##########
cpp/src/arrow/flight/serialization_internal.cc:
##########
@@ -376,6 +384,161 @@ 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_val.option_value_case()) {
+ case pb::SessionOptionValue::OPTION_VALUE_NOT_SET:
+ return Status::Invalid("Unset SessionOptionValue found");
+ case pb::SessionOptionValue::kStringValue:
+ *val = pb_val.string_value();
+ break;
+ case pb::SessionOptionValue::kBoolValue:
+ *val = pb_val.bool_value();
+ break;
+ case pb::SessionOptionValue::kInt32Value:
+ *val = pb_val.int32_value();
+ break;
+ case pb::SessionOptionValue::kInt64Value:
+ *val = pb_val.int64_value();
+ break;
+ case pb::SessionOptionValue::kFloatValue:
+ *val = pb_val.float_value();
+ break;
+ case pb::SessionOptionValue::kDoubleValue:
+ *val = pb_val.double_value();
+ break;
+ case pb::SessionOptionValue::kStringListValue:
+ (*val).emplace<std::vector<std::string>>();
+ std::get<std::vector<std::string>>(*val).reserve(
+ pb_val.string_list_value().values_size());
+ for (const std::string& s : pb_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);
+ }},
+ val);
+ return Status::OK();
+}
+
+// map<string, SessionOptionValue>
+
+Status FromProto(const google::protobuf::Map<std::string,
pb::SessionOptionValue>& pb_map,
+ std::map<std::string, SessionOptionValue>* map) {
+ if (pb_map.empty()) {
+ return Status::OK();
+ }
+ for (auto& [key, pb_val] : pb_map) {
Review Comment:
nit: prefer `const auto&` where possible
--
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]