| 179 | } |
| 180 | |
| 181 | absl::optional<CelValue> FlatBuffersMapImpl::operator[]( |
| 182 | CelValue cel_key) const { |
| 183 | if (!cel_key.IsString()) { |
| 184 | return CreateErrorValue( |
| 185 | arena_, absl::InvalidArgumentError( |
| 186 | absl::StrCat("Invalid map key type: '", |
| 187 | CelValue::TypeName(cel_key.type()), "'"))); |
| 188 | } |
| 189 | auto field = keys_.fields->LookupByKey(cel_key.StringOrDie().value().data()); |
| 190 | if (field == nullptr) { |
| 191 | return absl::nullopt; |
| 192 | } |
| 193 | switch (field->type()->base_type()) { |
| 194 | case reflection::Byte: |
| 195 | return CelValue::CreateInt64( |
| 196 | flatbuffers::GetFieldI<int8_t>(table_, *field)); |
| 197 | case reflection::Short: |
| 198 | return CelValue::CreateInt64( |
| 199 | flatbuffers::GetFieldI<int16_t>(table_, *field)); |
| 200 | case reflection::Int: |
| 201 | return CelValue::CreateInt64( |
| 202 | flatbuffers::GetFieldI<int32_t>(table_, *field)); |
| 203 | case reflection::Long: |
| 204 | return CelValue::CreateInt64( |
| 205 | flatbuffers::GetFieldI<int64_t>(table_, *field)); |
| 206 | case reflection::UByte: |
| 207 | return CelValue::CreateUint64( |
| 208 | flatbuffers::GetFieldI<uint8_t>(table_, *field)); |
| 209 | case reflection::UShort: |
| 210 | return CelValue::CreateUint64( |
| 211 | flatbuffers::GetFieldI<uint16_t>(table_, *field)); |
| 212 | case reflection::UInt: |
| 213 | return CelValue::CreateUint64( |
| 214 | flatbuffers::GetFieldI<uint32_t>(table_, *field)); |
| 215 | case reflection::ULong: |
| 216 | return CelValue::CreateUint64( |
| 217 | flatbuffers::GetFieldI<uint64_t>(table_, *field)); |
| 218 | case reflection::Float: |
| 219 | return CelValue::CreateDouble( |
| 220 | flatbuffers::GetFieldF<float>(table_, *field)); |
| 221 | case reflection::Double: |
| 222 | return CelValue::CreateDouble( |
| 223 | flatbuffers::GetFieldF<double>(table_, *field)); |
| 224 | case reflection::Bool: |
| 225 | return CelValue::CreateBool( |
| 226 | flatbuffers::GetFieldI<int8_t>(table_, *field)); |
| 227 | case reflection::String: { |
| 228 | auto value = flatbuffers::GetFieldS(table_, *field); |
| 229 | if (value == nullptr) { |
| 230 | return CelValue::CreateStringView(absl::string_view()); |
| 231 | } |
| 232 | return CelValue::CreateStringView( |
| 233 | absl::string_view(value->c_str(), value->size())); |
| 234 | } |
| 235 | case reflection::Obj: { |
| 236 | const auto* field_schema = schema_.objects()->Get(field->type()->index()); |
| 237 | const auto* field_table = flatbuffers::GetFieldT(table_, *field); |
| 238 | if (field_table == nullptr) { |
nothing calls this directly
no test coverage detected