Insert or update a protobuf message under an application-owned scope.
(
&self,
message: &T,
scope: &str,
)
| 341 | |
| 342 | /// Insert or update a protobuf message under an application-owned scope. |
| 343 | pub async fn put_scoped_message< |
| 344 | T: Message + ObjectType + ObjectId + ObjectName + ObjectLabels, |
| 345 | >( |
| 346 | &self, |
| 347 | message: &T, |
| 348 | scope: &str, |
| 349 | ) -> PersistenceResult<()> { |
| 350 | let labels_map = message.object_labels(); |
| 351 | let labels_json = if labels_map.as_ref().is_none_or(HashMap::is_empty) { |
| 352 | None |
| 353 | } else { |
| 354 | Some(serde_json::to_string(&labels_map).map_err(|e| { |
| 355 | PersistenceError::Encode(format!("failed to serialize labels: {e}")) |
| 356 | })?) |
| 357 | }; |
| 358 | |
| 359 | self.put_scoped( |
| 360 | T::object_type(), |
| 361 | message.object_id(), |
| 362 | message.object_name(), |
| 363 | scope, |
| 364 | &message.encode_to_vec(), |
| 365 | labels_json.as_deref(), |
| 366 | ) |
| 367 | .await |
| 368 | } |
| 369 | |
| 370 | /// Fetch and decode a protobuf message by id. |
| 371 | pub async fn get_message<T: Message + Default + ObjectType + SetResourceVersion>( |
no test coverage detected