I'm trying to write a packet protocol using golang. As the protocol will have a fixed length, it seems like a good starting point to allocate the exact amount of memory. E.g.
packet := make([]byte, 1024)
What I don't understand is how to then populate specific elements of that packet. I want to say something like:-
slice = pointer(packet[512])
slice = []byte("abcdef")
The result being that packet[512:518] == []byte("abcdef"). The docs I've read on Arrays and Slices show how to modify a single byte in a slice but not a contiguous sequence of bytes. Is there a method to do this?
You can’t do this. The closest way I can tell is use copy. check: http://play.golang.org/p/PtGJuVgEjc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With