If I have an existing []byte
, what is the recommended way to append the bytes of one or more uint32
value(s) to it?
For example, what should I replace // ???
with:
s := []byte{0x00, 0x01, 0x02, 0x03}
u := uint32(0x07060504)
// ???
fmt.Println(s) // Should print [0 1 2 3 4 5 6 7]
Edit: One option would be s = append(s, byte(u)); s = append(s, byte(u >> 8)); s = append(s, byte(u >> 16)); s = append(s, byte(u >> 24))
, but is there a more idiomatic way to do this? Perhaps using package binary and/or package bytes?