CopyReplace works similarly to Replace except that the returned byte slice does not point to the same memory as 'raw'. CopyReplace returns 'nil' if the field doesn't exist or 'raw' isn't a map.
(key string, raw []byte, val []byte)
| 32 | // byte slice does not point to the same memory as 'raw'. CopyReplace |
| 33 | // returns 'nil' if the field doesn't exist or 'raw' isn't a map. |
| 34 | func CopyReplace(key string, raw []byte, val []byte) []byte { |
| 35 | start, end := locate(raw, key) |
| 36 | if start == end { |
| 37 | return nil |
| 38 | } |
| 39 | return replace(raw, start, end, val, false) |
| 40 | } |
| 41 | |
| 42 | // Remove removes a key-value pair from 'raw'. It returns |
| 43 | // 'raw' unchanged if the key didn't exist. |
searching dependent graphs…