Inject a string field into a msgpack map without full decode. If `value` is a valid msgpack map that already contains `field_name`, the existing value is preserved and the input is returned unchanged — the caller's body is authoritative for its own primary key. If the map does not contain the field, it is prepended. If `value` is not a map, wraps as `{field_name: field_value, "value": raw}`.
(value: &[u8], field_name: &str, field_value: &str)
| 169 | /// does not contain the field, it is prepended. If `value` is not a map, |
| 170 | /// wraps as `{field_name: field_value, "value": raw}`. |
| 171 | pub fn inject_str_field(value: &[u8], field_name: &str, field_value: &str) -> Vec<u8> { |
| 172 | if let Some((count, body_start)) = crate::msgpack_scan::reader::map_header(value, 0) { |
| 173 | if crate::msgpack_scan::extract_field(value, 0, field_name).is_some() { |
| 174 | return value.to_vec(); |
| 175 | } |
| 176 | let mut buf = Vec::with_capacity(value.len() + field_name.len() + field_value.len() + 16); |
| 177 | write_map_header(&mut buf, count + 1); |
| 178 | write_kv_str(&mut buf, field_name, field_value); |
| 179 | buf.extend_from_slice(&value[body_start..]); |
| 180 | buf |
| 181 | } else { |
| 182 | let mut buf = Vec::with_capacity(value.len() + field_name.len() + field_value.len() + 16); |
| 183 | write_map_header(&mut buf, 2); |
| 184 | write_kv_str(&mut buf, field_name, field_value); |
| 185 | write_str(&mut buf, "value"); |
| 186 | buf.extend_from_slice(value); |
| 187 | buf |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | /// Merge field updates into a msgpack map without full decode. |
| 192 | /// |
no test coverage detected