incBytes increments a byte slice, which involves incrementing the right-most byte, and following carry leftward. It makes a copy so that the provided slice's underlying array is not modified. If the overall operation overflows (e.g. incBytes(0xff, 0xff)), the second return parameter indicates that.
(in []byte)
| 1242 | // It makes a copy so that the provided slice's underlying array is not modified. |
| 1243 | // If the overall operation overflows (e.g. incBytes(0xff, 0xff)), the second return parameter indicates that. |
| 1244 | func incBytes(in []byte) (out []byte, overflow bool) { |
| 1245 | out = make([]byte, len(in)) |
| 1246 | copy(out, in) |
| 1247 | for i := len(out) - 1; i >= 0; i-- { |
| 1248 | out[i]++ |
| 1249 | if out[i] != 0 { |
| 1250 | return // Didn't overflow. |
| 1251 | } |
| 1252 | } |
| 1253 | overflow = true |
| 1254 | return |
| 1255 | } |
no outgoing calls