viem-goviem-go

isBytes

Checks if a value is a byte slice

isBytes

Checks if a value is a byte slice ([]byte).

Import

import "github.com/ChefBingbong/viem-go/utils/data"

Usage

import "github.com/ChefBingbong/viem-go/utils/data"
// Valid byte slice
valid := data.IsBytes([]byte{0x01, 0x02})
// true
// Not a byte slice
valid = data.IsBytes("0x0102")
// false
// Nil is not bytes
valid = data.IsBytes(nil)
// false

Returns

  • Type: bool

true if the value is a byte slice, false otherwise.

Parameters

value (required)

  • Type: any

The value to check.

valid := data.IsBytes([]byte{0x01, 0x02})
// true
valid = data.IsBytes("0x0102")
// false
valid = data.IsBytes(nil)
// false

Notes

  • In Go, this is primarily useful for type assertions in generic contexts
  • Returns false for nil values
  • Only returns true for actual []byte types, not other slice types