| 419 | } |
| 420 | |
| 421 | Result<std::shared_ptr<Buffer>> SubstraitFromJSON(std::string_view type_name, |
| 422 | std::string_view json, |
| 423 | bool ignore_unknown_fields) { |
| 424 | std::string type_url = "/substrait." + std::string(type_name); |
| 425 | |
| 426 | google::protobuf::io::ArrayInputStream json_stream{json.data(), |
| 427 | static_cast<int>(json.size())}; |
| 428 | |
| 429 | std::string out; |
| 430 | google::protobuf::io::StringOutputStream out_stream{&out}; |
| 431 | google::protobuf::util::JsonParseOptions json_opts; |
| 432 | json_opts.ignore_unknown_fields = ignore_unknown_fields; |
| 433 | auto status = google::protobuf::util::JsonToBinaryStream( |
| 434 | GetGeneratedTypeResolver(), type_url, &json_stream, &out_stream, |
| 435 | std::move(json_opts)); |
| 436 | |
| 437 | if (!status.ok()) { |
| 438 | return Status::Invalid("JsonToBinaryStream returned ", status); |
| 439 | } |
| 440 | return Buffer::FromString(std::move(out)); |
| 441 | } |
| 442 | |
| 443 | Result<std::string> SubstraitToJSON(std::string_view type_name, const Buffer& buf) { |
| 444 | std::string type_url = "/substrait." + std::string(type_name); |