| 81 | } |
| 82 | |
| 83 | std::string VariableShapeTensorType::Serialize() const { |
| 84 | JsonWriter writer; |
| 85 | |
| 86 | writer.StartObject(); |
| 87 | |
| 88 | if (!permutation_.empty()) { |
| 89 | writer.Key("permutation"); |
| 90 | writer.StartArray(); |
| 91 | for (auto v : permutation_) { |
| 92 | writer.Int64(v); |
| 93 | } |
| 94 | writer.EndArray(); |
| 95 | } |
| 96 | |
| 97 | if (!dim_names_.empty()) { |
| 98 | writer.Key("dim_names"); |
| 99 | writer.StartArray(); |
| 100 | for (const auto& v : dim_names_) { |
| 101 | writer.String(v); |
| 102 | } |
| 103 | writer.EndArray(); |
| 104 | } |
| 105 | |
| 106 | if (!uniform_shape_.empty()) { |
| 107 | writer.Key("uniform_shape"); |
| 108 | writer.StartArray(); |
| 109 | for (const auto& v : uniform_shape_) { |
| 110 | if (v.has_value()) { |
| 111 | writer.Int64(*v); |
| 112 | } else { |
| 113 | writer.Null(); |
| 114 | } |
| 115 | } |
| 116 | writer.EndArray(); |
| 117 | } |
| 118 | |
| 119 | writer.EndObject(); |
| 120 | |
| 121 | Result<std::string_view> json = writer.GetString(); |
| 122 | // can only fail in OutOfMemory scenarios |
| 123 | ARROW_CHECK_OK(json.status()); |
| 124 | return std::string(*json); |
| 125 | } |
| 126 | |
| 127 | Result<std::shared_ptr<DataType>> VariableShapeTensorType::Deserialize( |
| 128 | std::shared_ptr<DataType> storage_type, const std::string& serialized_data) const { |