size
Returns the size of a hex string or byte slice in bytes
Loading...
Returns the size of a hex string or byte slice in bytes
Returns the size of a hex string or byte slice in bytes.
import "github.com/ChefBingbong/viem-go/utils/data"import "github.com/ChefBingbong/viem-go/utils/data"
// Get size of hex stringsize := data.SizeHex("0x0102")// 2
// Get size of byte slicesize := data.SizeBytes([]byte{0x01, 0x02, 0x03})// 3
// Generic size function (works with both)size := data.Size("0x0102")// 2
size = data.Size([]byte{0x01, 0x02})// 2intThe size in bytes. For hex strings, calculates the byte length from hex characters (rounds up for odd lengths).
string for SizeHex, []byte for SizeBytes, any for SizeThe hex string or byte slice to measure.
// Hex string sizesize := data.SizeHex("0x0102")// 2
// Byte slice sizesize := data.SizeBytes([]byte{0x01, 0x02, 0x03})// 3
// Generic size (auto-detects type)size := data.Size("0x0102")// 2
size = data.Size([]byte{0x01, 0x02})// 2(hexLength + 1) / 2 to handle odd-length hex strings"0x") return 00x prefix