Update a leaf's content.
(
txn: &mut T,
leaf_id: LeafId,
new_content: &[u8],
)
| 1150 | |
| 1151 | /// Update a leaf's content. |
| 1152 | fn update_leaf_content<T: MutTxnT>( |
| 1153 | txn: &mut T, |
| 1154 | leaf_id: LeafId, |
| 1155 | new_content: &[u8], |
| 1156 | ) -> PristineResult<()> { |
| 1157 | let key = encode_leaf_id(&leaf_id); |
| 1158 | |
| 1159 | // Get existing leaf |
| 1160 | if let Some(mut serialized) = txn.get_crdt_leaf(&key)? { |
| 1161 | // Update content range (actual content is in the change's content blob) |
| 1162 | serialized.content_end = serialized.content_start + new_content.len() as u32; |
| 1163 | |
| 1164 | // Re-encode and store |
| 1165 | let value = encode_leaf_value(&serialized); |
| 1166 | txn.put_crdt_leaf(&key, &value)?; |
| 1167 | } |
| 1168 | |
| 1169 | Ok(()) |
| 1170 | } |
| 1171 | |
| 1172 | // Tests |
| 1173 |
no test coverage detected