Open
Description
the current situation of when padding occurs is not very consistent and requires a confusing workaround to cast a bytes
item to a certain size
// from int to bytes
bytes(int) -> typecast
bytes6(int) -> padding
bytes(int, 6) -> padding
// from bytes to bytes
bytes6(bytes) -> typecast
bytes6(int(bytes)) -> padding
bytes(int(bytes), 6) -> padding
I suggest a new function toBytesX(item, byteLength)
which takes care of the padding
So the new way would be
// from int to bytes
bytes(int) -> typecast
toBytesX(int, 6) -> padding
// from bytes to bytes
bytes6(bytes) -> typecast
toBytesX(bytes, 6) -> padding
possible alternative syntaxes toBytesLength
, padBytes
, or resizeBytes
.
what would break
The second argument in bytes(item, length)
would simply be deprecated, this can be done over time, first with a warning.
bytes6(int)
would simply be disallowed and result in a type error at compile time, only bytes
type would be able to cast to a bounded bytes type