I'm working with a HID driver, and this driver reads onto a []byte
buffer one of a few different reports. When I use hex.EncodeToString(buffer)
, it will return a string looking like either 0000
or 0100
or 0200
, etc. I want to check, using a switch, against the input from the HID device, and so I want to predefine these possibilities, up outside the main()
, how should I proceed?
I've tried these possibilities:
var LEFT []byte = []byte('0000')
// or
var LEFT []byte = `0000`
// or
var LEFT []byte = '0000'
// or
var LEFT []byte = '\x00\x00' // from the %q Printf verb
The alternative is that I call hex.DecodeString("0000")
inside the main() function.
Edit
A note on the solution offered, the EncodeToString
hex 0000
or 0100
is not four bytes but rather two:
"\x01"
== "01"
== '1'
so I can use, in order to get 0100, or 0200, as suggested:
var LEFT []byte{1,0}
// or
var LEFT []byte("\x01\x00")