bytes_edit
Edit hex byte-buffers: pad, trim, slice, concat, size, or manage 0x prefix. Returns modified buffer and byte length.
Instructions
Edit a hex byte-buffer: pad/trim to width, slice, concat, size, or 0x-prefix.
data is hex (a leading 0x is optional). Actions:
pad: widen to
lengthbytes with thefillbyte onside(left=prepend, right=append); never truncates if already wider.trim: strip the
fillbyte (default 00) fromside(left=leading, right=trailing) — the inverse of pad.slice: take
data[start:end](Python indexing; negatives allowed).concat: append each hex buffer in
partstodata.size: report the byte length, buffer unchanged.
prefix: side=left adds a 0x prefix, side=right strips it.
Returns {action, result, size}: result is the 0x-prefixed hex buffer (bare
hex when prefix-stripping), size its byte length.
Example: a 20-byte address -> 32-byte log topic:
bytes_edit("pad", "0x1234", length=4, side="left") -> result "0x00001234"
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Edit to apply: pad (widen to `length`), trim (strip `fill`), slice (`start`:`end`), concat (append `parts`), size (report byte length), prefix (add/strip 0x). | |
| data | Yes | Input byte-buffer as hex, a leading 0x is optional. | |
| length | No | Target byte width for action=pad. Default None. | |
| start | No | Slice start index (Python indexing, negatives allowed); default None means 0. | |
| end | No | Slice end index (Python indexing, negatives allowed); default None means end of buffer. | |
| parts | No | Hex buffers to append for action=concat. Default None. | |
| side | No | Which side acts: pad prepend/append, trim leading/trailing, prefix add/strip 0x. Default 'left'. | left |
| fill | No | The pad/trim byte as one hex byte (0x optional); default '00'. | 00 |