Update a leaf's content.
(
txn: &mut T,
leaf_id: LeafId,
new_content: &[u8],
)
| 990 | |
| 991 | /// Update a leaf's content. |
| 992 | fn update_leaf_content<T: MutTxnT>( |
| 993 | txn: &mut T, |
| 994 | leaf_id: LeafId, |
| 995 | new_content: &[u8], |
| 996 | ) -> PristineResult<()> { |
| 997 | let key = encode_leaf_id(&leaf_id); |
| 998 | |
| 999 | // Get existing leaf |
| 1000 | if let Some(mut serialized) = txn.get_crdt_leaf(&key)? { |
| 1001 | // Update content range (actual content is in the change's content blob) |
| 1002 | serialized.content_end = serialized.content_start + new_content.len() as u32; |
| 1003 | |
| 1004 | // Re-encode and store |
| 1005 | let value = encode_leaf_value(&serialized); |
| 1006 | txn.put_crdt_leaf(&key, &value)?; |
| 1007 | } |
| 1008 | |
| 1009 | Ok(()) |
| 1010 | } |
| 1011 | |
| 1012 | // Tests |
| 1013 |
no test coverage detected